c# - Collecting data from a strongly typed razor view -


it's first asp.net mvc application @ all. i'm using mvc 3 , razor views. specific view have problem strongly-typed view (at least think is) accepts type of kind :

@model list<list<dataaccess.mcs_documentfields>[]> 

i made several partial view because main view customized , need lot of different logic different parts of data. partial view typed (again think correct say) of type :

@model list<dataaccess.mcs_documentfields>[] 

everything need build view in :

@using (html.beginform("actionmethodname", "forms", formmethod.post)) {     <div id="drawform">         <table border="1"> 

inside hhtml.beginform build table data comes controller. on submit :

<button type="submit">submit</button> 

i'm looking best way data, , update in database changed. in controller have method :

[httppost]         public actionresult actionmethodname(formcollection collection)         {             var test = collection;             list<mcs_documents> model = documentsservice.all().tolist();             return view("index", model);         } 

this way can find data, it's complicated, i'm not sure how i'll it. tried else, using same method accepting argument type view accepts :

[httppost]             public actionresult actionmethodname(list<list<dataaccess.mcs_documentfields>[]> collection)             { 

but when collections has null value. , little know when use strongly-typed view can additional advantages form.validation , data binding ready update , on...

so best way, in specific scenario, deal data submitted form?

p.s

this how render main view :

<table border="1">             <colgroup>             <col span="1" style="width: 10%;" />             <col span="1" style="width: 40%;" />             <col span="1" style="width: 25%;" />             <col span="1" style="width: 25%;" />             </colgroup>             <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 partials, showcase how use them :

@model list<dataaccess.mcs_documentfields>[]          <tr>                           @if (!string.isnullorempty(model[0][0].fieldvalue))                 {                      <td colspan="2">                     @html.displayfor(x => x[0][0].fieldvalue)                     </td>                 }                 else                 {                      <td colspan="2">                     sign in here                     </td>                 }                           @if (!string.isnullorempty(model[1][0].fieldvalue))                 {                      <td colspan="2">                     @html.displayfor(x => x[1][0].fieldvalue)                     </td>                 }                 else                 {                      <td colspan="2">                     sign in here                     </td>                 }                  </tr> 

that last action method correct (which takes strong type), views need structured differently. need make sure every collection (even sub collections) correctly indexed, otherwise model binding fail.

your views should following (note use of for loops):

main view:

@model list<list<dataaccess.mcs_documentfields>[]>  @for (int = 0; < model.count; i++) {     @html.renderpartial("partialname", model[i]) } 

then in partial:

  @model list<dataaccess.mcs_documentfields>[]    @for (int = 0; < model.count; i++)   {       //not sure if need @ level       (int j = 0; j < model[i].count(); j++)       {           //add editorfor's, hiddenfor's etc child type       }   } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -