i new mvc.net 5; developing application dropdowns , forms. dropdowns created model , cant fugure out how take falues dropdowns. here part of code:
first dropdown partial view:
@using system.data.sqlclient @model cars.web.models.testmodel @using (ajax.beginform("getbymake", "cars", null, new ajaxoptions { httpmethod = "post", updatetargetid = "models", insertionmode = insertionmode.replace }, new { id = "selectmarke" })) { @html.dropdownlistfor( m => m.selectedmarkeid, new selectlist(model.markes, "id", "name"), string.empty ) } <script> $('#selectedmarkeid').change(function () { console.log("asd"); $('#selectmarke').submit(); }); </script>
here second:
@model cars.web.models.testmodel @if (model.models != null && model.models.any()) { @html.dropdownlist( "models", new selectlist(model.models, "id", "modelname"), string.empty ) }
i can pass firstone id second 1 form controller, think, not right way. wonder if add more forms, how bind them 2 drop down on submit. thanks
when use:
@html.dropdownlistfor( m => m.selectedmarkeid, new selectlist(model.markes, "id", "name"), string.empty )
the name
of dropdownlist "selectedmarkeid".
when use:
@html.dropdownlist( "models", new selectlist(model.models, "id", "modelname"), string.empty )
the name
of dropdownlist "models"
the controller must have parameters match name
of inputs. this:
[httppost] public actionresult someaction (int models, int selectedmarkeid) { //selectedmarkeid selected value of first drop down list //models selected value of second drop down list //your code here }
you can use object, contains properties match names of inputs. this:
public class testmodel { public int models { get; set; } public int selectedmarkeid { get; set; } } [httppost] public actionresult someaction (testmodel model) { //selectedmarkeid selected value of first drop down list //models selected value of second drop down list //your code here }
Comments
Post a Comment