ASP.Net MVC EditorFor not working -


i trying render table, using editorfor, , partialview, think.

i have model list<> property defined this:

public list<transactionsplitline> transactionsplitlines { get; set; } 

the idea user selects few drop downs , enters value edit box, , clicks button. model goes controller, , controller adds entered values list<>

[httppost] public actionresult accounttransaction(accounttransactionview model) {     var reply = createmodel(model);     if (model.categoryids != null)     {         foreach (var c in model.categoryids)         {             reply.transactionsplitlines.add(new transactionsplitline { amount = "100", category = "test category", subcategory = "test more", categoryid = int.parse(c) });         }     }     reply.transactionsplitlines.add(new transactionsplitline { amount = "100", category = "test category", subcategory = "test more", categoryid = 1 });     return view("accounttransaction", reply); } 

ignore createmodel. sets data. also, hardcoding data. come form values.

the model returned same screen, allowing user ender more data. items in list<> read , table rendered. have store current listen item values in hidden fields, can submitted back, along new data entered, list can grow each time user adds data.

the view defined this:

<table width="600">     <thead>         <tr class="headerrow">             <td>                 category             </td>             <td>                 sub category             </td>             <td>                 amount             </td>         </tr>     </thead>     <tbody>         <%=html.editorfor(m=>m.transactionsplitlines) %>     </tbody> </table> 

this first attempt editorfor...

my view in folder 'views/bankaccount/accounttransaction.aspx

i have created ascx in views/shared/transactionsplitlines.ascx

the code ascx this:

<%@ control language="c#" inherits="system.web.mvc.viewusercontrol<budgiemoneysite.models.transactionsplitline>" %>   <tr>     <td>         <%=model.category %>         <%=html.hiddenfor(x => x.categoryid)%>     </td>     <td>         <%=model.subcategory %>         <%=html.hiddenfor(x => x.subcategoryid)%>     </td>     <td>         <%=model.amount %>         <%=html.hiddenfor(x => x.amountvalue)%>     </td>  </tr> 

this data

the 'this data' test stuff, never rendered.

when run this, happens output rendered as:

<table width="600">     <thead>         <tr class="headerrow">              <td>                 category             </td>             <td>                 sub category             </td>             <td>                 amount             </td>         </tr>      </thead>     <tbody>         test category     </tbody> </table> 

it seems ascx isn't being used? i'd expect see 'this data' text. but, nothing. can see obvious fault?

your editor template should either:

~/views/shared/editortemplates/transactionsplitline.ascx 

or:

~/views/bankaccount/editortemplates/transactionsplitline.ascx 

the name of ascx type name of collection item (transactionsplitline , not transactionsplitlines) , should situated @ ~/views/shared/editortemplates or ~views/controllername/editortemplates.

or if want use custom editor template name:

<%= html.editorfor(m=>m.transactionsplitlines, "~/views/foo.ascx") %> 

or use uihintattribute on model.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -