c# - Determine the type of an action method argument recieving data from strongly typed view -
i have following problem - developing asp.net mvc 3 application , have view typed. because of complexity of data model in view looks :
@model list<list<dataaccess.mcs_documentfields>[]>
then render view :
@using (html.beginform("actionmethodname", "forms")) { <table border="1"> <tbody> @for (int = 0; < model.count(); i++) { if (model[i][0][0].contenttypeid == 1) { @html.partial("_partialheader", model[i]) } else if (model[i][0][0].contenttypeid == 2) { @html.partial("_partialdrawing", model[i]) } else if (model[i][0][0].contenttypeid == 3) { @html.partial("_partialbody", model[i]) } else if (model[i][0][0].contenttypeid == 4) { @html.partial("_partialfooter", model[i]) } } </tbody> </table> <button type="submit">save</button> }
and 1 of partial views :
if (string.isnullorempty(item.fieldvalue)) { <td colspan="2"> @html.displayfor(y => y[i][0].questiontext) @html.hiddenfor(y => y[i][0].questiontext) </td> } else { <td colspan="2"> @html.displayfor(y => y[i][0].questiontext) @html.hiddenfor(y => y[i][0].questiontext) : @html.displayfor(y => y[i][0].fieldvalue) @html.hiddenfor(y => y[i][0].fieldvalue) </td> }
this snippet, want table has @ least 8-9 rows , each row has @html.hiddenfor
expect data when i'm submiting form.
in controller have method :
[httppost] public actionresult actionmethodname(list<mcs_documentfields>[] collection) { var test = collection; list<mcs_documents> model = documentservice.all().tolist(); return view("index", model); }
i tried lot of different types collection
argument. of time null, @ best first 2 row (no idea why first two) nothing more. if use formcollection
have submitted data, it's not related mcs_documentfields
class in way.
i don't know i'm doing wrong. don't think type method should guessed think must determined , if there problem in code (most possibly in partial view) because i've posted here of main view, suggestions why logic not working , why can't bind data original type of model?
i suggest @ begincollectionitem package (http://nuget.org/packages/begincollectionitem/), allthough can see model complex (3 dimensions), sou you'll have nest them in nasty manner.
also should consider (due model complexity) creating custom model binder (http://www.codeproject.com/articles/605595/asp-net-mvc-custom-model-binder).
just 1 last remark - model in view differs model expect in action:
list<mcs_documentfields>[] collection != list<list<dataaccess.mcs_documentfields>[]>
ivan
Comments
Post a Comment