c# - Why Is My ASP.NET MVC Model Filled in the Controller, but Null in the View? -



c# - Why Is My ASP.NET MVC Model Filled in the Controller, but Null in the View? -

i have dumb issue that's going on.

i have asp.net mvc page absolutely refuses display viewmodel. if remove database results assigned viewmodel , hardcode value want in viewmodel property within of controller, still doesn't work. during debugging, can see proper info placed within of viewmodel within controller, view acts never gets it. using quickwatch, can see info within of field.

it display names of variable it's using in labelfors, never display variable's value in text box.

view

@model project1.viewmodels.ordernolocationviewmodel @{ html.enableclientvalidation(); } @using (html.beginform()) { @html.antiforgerytoken() <table class="item-display" style="width: 100%;"> <tr> <td class="label"> <div class="editor-label">@html.labelfor(model => model.shipper):</div> </td> <td class="value"> <div class="editor-field"> @html.textboxfor(model => model.shipper) @html.validationmessagefor(model => model.shipper) </div> </td> </table> }

controller

[httppost] [validateantiforgerytoken()] public actionresult index(ordernolocationviewmodel model, string consigneefilter, string ordernofilter, string button) { model = new ordernolocationviewmodel() { shipper = "ray" }; homecoming view(model); }

i have no earthly thought going on... have other pages work, , literally page acting this.

please help! :(

edit:

routes

public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults ); }

its not exclusively clear trying here or why doing way. if want display form edit properties of ordernolocationviewmodel display method

public actionresult index() { var model = model = new ordernolocationviewmodel(); model.shipper = "ray"; homecoming view(model); }

the textbox display "ray".

when post to

[httppost] public actionresult index(ordernolocationviewmodel model) { }

model.shipper contain value of whatever in textbox (which "ray" if user has not altered value).

reassigning model have done here in post method

model = new ordernolocationviewmodel() { shipper = "ray" }; homecoming view(model);

has no impact unless clear modelstate (the view takes values modelstate). assume in case initial value of shipper null or string.empty when view returned, still null or string.empty see work, amend post method to

[httppost] public actionresult index(ordernolocationviewmodel model) { modelstate.clear(); model.shipper = "some other value"; homecoming view(model); }

the text box contain "some other value". not want since clearing modelstate removes validation errors well

c# asp.net-mvc asp.net-mvc-4

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -