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

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.

Related

Razor Checkbox calling ControllerAction in Asp.Net MVC?

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

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();

Dynamic Drop Down List ASP.net

How can I create a dynamic drop down list without using AutoPostBack. I ask because I just want to change the value of what the second drop down list displays and then the user clicks a button and it submits. But If I use AutoPostBack then it postbacks to page and runs code that shouldn't be run until that final box has been selected. (I use Postback in the other part of my program so using !IsPostBack isnt a option.) I looked at Javascript but ASP generates all of its controls names at runtime. What can I do? I have looked at the Ajax CascadingDropDown control but my problem with that is it contained in a XML file or a Database, I need this to be contained inside my Page. Any Ideas?
You can use the CascadingDropDown control from the AJAX Control Toolkit
Maybe this example will help? It's part of the ASP.NET AJAX Control Toolkit available here.
You can use AJAX to get the values for the second drop down list, based on the selected value of the first. Add a onchange event handler on the client-side to the first drop down list that makes the AJAX call and fills the second on success.

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.

How to trigger RenderAction from dropdown list selection?

I have an ajax form.
In this form i have 2 drop down lists (Office and Departments) and a "Filter" Button.
When filter button is clicked my ajax form is set to update "content_main" with my new filtered list.
My question is... how can i get Office (when a selection is made) to trigger a RenderAction on the DIV element containing my list of dependent departments (over writing it with a dropdown list of Departments in that office)?
Hope this makes sense,
Thanks in advance for any help,
Kohan.
I fixed it,
I have an onchange event on my dropdown that fires an ajax call to my PartialViewAction, this returns a partial containing my dropdown list bound to the model i want and then this overwrites my container DIV.html.
job done.

Categories

Resources