c# - How can I call EditorFor from the controller -


i have list of locations

public class location {     public string locationname { get; set; }     public string address { get; set; } } 

i created editor template class

<div>    <span>@html.textboxfor(a => a.locationname)</span>    <span style="color: red;">@html.textboxfor(a => a.address )</span> </div> 

the problem locations load ajax page , going send results server. how location specific index? mean first location generate this:

<input type="text" name="locations[0].locationname" /> 

for second location when press "add location" button should location server (from action of controller html string) index 1 not 0 because next location.

is possible achieve it? or doing wrong?

something this

    [httpget]     public virtual actionresult locationeditor(int index)     {         viewdata.templateinfo.htmlfieldprefix = string.format("locations[{0}]", index);         return partialview(@"editortemplateexplicitpathasonlyviewnameaintgonnawork.cshtml");     } 

and location names container

<div class="locations-container" data-item-count="@model.count">     @for (int j = 0; j < model.count; j++)     {         @html.editorfor(model => model[j])     }     <a href="#" class="add-location">add location</a> </div> 

the rest of tiny bit of javascript increment data-item-count upon adding , call locationnameeditorlocationnameeditor action new index upon you.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -