c# - MVC 2 Form Values not posting -


hey attempting learn mvc 2 , asp etc through mvc music store. @ same time attempting conform doing solution developing @ work. overall structure desk ticket system , working on broad admin functions of creating, editing, , deleting tickets. have followed tutorial closely have hit brick wall, when attempting use values should getting posted controller methods, , theyre not getting there.

for create section create.aspx looks like

<h2>create</h2> <% html.enableclientvalidation(); %> <% using (html.beginform()) {%>     <%: html.validationsummary(true) %>      <fieldset>         <legend>create new request</legend>         <%: html.editorfor(model => model.request,                new {softwares = model.softwarename, systems = model.systemidno}) %>          <p>             <input type="submit" value="create" />         </p>     </fieldset>  <% } %>  <div>     <%: html.actionlink("back list", "index") %> </div> 

the partial view calling workrequest.ascx

<p>      <%= html.labelfor(model => model.medium)%>      <%= html.textboxfor(model => model.medium)%>     <%= html.validationmessagefor(model => model.medium)%>  </p>  <p>      <%= html.labelfor(model => model.summary)%>      <%= html.textboxfor(model => model.summary)%>      <%= html.validationmessagefor(model => model.summary)%>  </p>  <p>      <%= html.labelfor(model => model.details)%>      <%= html.textareafor(model => model.details)%>      <%= html.validationmessagefor(model => model.details)%>  </p> <p>      <%= html.labelfor(model => model.workhalted)%>      <%= html.textboxfor(model => model.workhalted)%>       <%= html.validationmessagefor(model => model.workhalted)%>  </p> <p>      <%= html.labelfor(model => model.frequency)%>      <%= html.textboxfor(model => model.frequency)%>     <%= html.validationmessagefor(model => model.frequency)%>  </p> <p>      <%= html.labelfor(model => model.startdate)%>      <%= html.textboxfor(model => model.startdate, string.format("{0:g}", model.startdate))%>      <%= html.validationmessagefor(model => model.startdate)%>  </p> <p>     <%= html.labelfor(model => model.softwareid) %>     <%= html.dropdownlist("softwareid", new selectlist(viewdata["softwares"] ienumerable, model.softwareid)) %> </p> <p>     <%= html.labelfor(model => model.systemid) %>     <%= html.dropdownlist("systemid", new selectlist(viewdata["systems"] ienumerable, model.systemid)) %> </p> 

and post create controller looks like

[httppost]     public actionresult create(workrequest newrequest)     {         try         {             storedb.addtoworkrequests(newrequest);             storedb.savechanges();              return redirecttoaction("index");         }         catch         {             return view();         }      } 

i put break point in try , checked values coming newrequest , in newrequest null, nothing getting passed.

a similar situation occurs on edit side of things well, nothing getting sent partial view controller @ all.

anyways sure simple, new mvc, asp, c#, pretty of it. dont ask other people much, have been looking @ problem quite time , use fresh eyes on one.

thanks in advance!

try using same view model type parameter used render view , typed:

[httppost] public actionresult create(viewmodelusedtostronglytypetheview model) {     //model.request should bound here     try     {         storedb.addtoworkrequests(model.request);         storedb.savechanges();         return redirecttoaction("index");     }     catch     {         return view(model);     } } 

or using prefix:

[httppost] public actionresult create([bind(prefix = "request")] workrequest newrequest) {     //model.request should bound here     try     {         storedb.addtoworkrequests(newrequest);         storedb.savechanges();         return redirecttoaction("index");     }     catch     {         return view();     } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -