Razor Checkbox calling ControllerAction in Asp.Net MVC? - c#

I have a Database that contains several Booleans. I'm displaying this database in my View but I want the user to be able to change the value behind the checkbox.
Is it possible to define some kind of onChange or onClick event for Html Checkboxes in Razor? Kind of like an Action link, so I can call the corresponding Controller Action to change the value?
Preferably without having to use too much JS or AJAX

Related

dropdown list selected index changed razor

I am using razor view engine(cshtml) outside of mvc framework. i.e only view is converted to cshtml format.
I make all database calls using webmatrix and construct cshtml view.
Although, now i want to fire dropdown list selected change event which will set or fill contents of another dropdown list on the same page.
Currently I use dropdown list using
#HTML.DropdownList("ID",List)
on the selectedindex change of dropdown, i wish to check it's value and then decide on whether or not to populate second dropdown.
How can I do it in this scenario? Remember, no mvc framework, hence no access to models or mvc specific methods.
when the dropdown list is rendered in the browser, it simply becomes a HTML tag and you can use vanilla javascript or frameworks like jQuery to check the item selected and load the next dropdown.
Sample:
$( "#myselect option:selected" ).text();

How to add multiple values into a page, and then to controller in ASP.Net MVC

I have this scenario to implement in ASP.Net MVC.
In my view, I would like to have a dropdown with a button , where on click of Button, will add selected values into probably a Div table. There will be a separate 'Save' button which will call the ActionResult POST method to save these values to the database.
Here, I could probably use AJAX to add values into the Div (However I am not sure how I can pass the values here to the controller once user clicks on the 'Save' button).
I was also thinking I could probably do a postback and add the values into a Session value (Probably an ASP.Net Web Form technique?) and call the ActionResult POST Method once the user clicks a separate 'Save' button.
Hence, in an ASP.Net MVC framework, what would be the best way to implement this scenario?
Thanks.
You can put all you hml into a #html form and then on save buton click you can either post that for to server or you can write a click event of that form by making ajax call.In ajax call you can send form data by form.serialize method.

How to get the value of html input in aspx view page in mvc?

I want to access the radio button value in aspx view page in middle of the logic.if value is checked i need to run for each loop to get the values or if radio button is unchecked no need of getting the values.
How to get the value of radio button in aspx view engine ?
From your title I get that you are using Asp.net MVC, if it is right you can define a parameter in your action method with the ID of your radiobutton, and MVC model binder will handle the remaining, you can use the parameter to check and run the loop.

Fill second select with onchange of first one on MVC3 without javascript

i have a project on MVC3 and Razor.
I'm doing on my project everything without javascript first and then in the future when everything works without JS, then i will add the JS functionallity.
The thing is that i have a razor page, that i fill from the Model a select and what i need is that when the select option changes, then another select must be filled.
My idea is that in the Model i have a collection of the object that needs the second select to get filledm, and when the onchange event of the first select is triggered, i call a method on the controller that fills the list on the model and in the view side, i fill the second select with a foreach over the list.
My question is.. how do i fire the onchange event on a ?
Notice that i'm not using Html.DropDownList or something like that.. but if it´s necessary, i will.
Thanks and i hope you can hellp me!
The select onchange event requires Javascript. To handle when Javascript is disabled you usually add something like an "Update" submit button within <noscript> tags to update the selection using a server post. The <noscript> tags will only show when Javacript is disabled.

How to pass a parameter from javascript to a UserControl?

In my ASP.Net application, there's a UserControl called EmployeesUserControl which is shown through a JQuery modal dialog.
Before showing the Employees, I've got to pass a filter criteria which is the entity that the employee is belong to. My question is that how can I pass the value from javascript to the UserControl?
What I tried so far is that I created a HiddenControl called SelectedEntityHiddenControl and I set it a value before showing the popup, hence, when the popup is shown and the Page_Load event handler of the UserControl is called, then I read the value of the hidden control and filter by it. But I don't think it's a good implementation what I've already done.
Any suggestion!
I think it's a good solution. I'm also using HiddenFields to pass values from JS to the ASP.NET Engine and back.
You've to ensure that your values are passed to the asp.net engine at the correct moment within the lifecycle.

Categories

Resources