问题描述:

I need to move items up and down, to have ability delete and add.

I can do it on server side, but I believe that this can be done on client side too, using javascript of sort. I am new in Web development and I will greatly appreciate if some one can give me some examples or point out direction how can i achieve my goal.

@for (int i = 0; i < Model.Items.Count; i++)

{

<tr>

<td>@Html.EditorFor(model => model.Items[i].Id)@Html.HiddenFor(model => model.Items[i].Id)</td>

<td>@Html.EditorFor(model => model.Items[i].Type)@Html.HiddenFor(model => model.Items[i].Type)</td>

<td>@Html.EditorFor(model => model.Items[i].Address)@Html.HiddenFor(model => model.Items[i].Address)</td>

</tr>

}

网友答案:

In order to do the rendering you should look into a javascript template engine like:

Handlebars (http://handlebarsjs.com/) Mustache: (http://mustache.github.io/)

There are many others, but they will allow you to append new rows to your table via javascript, or you can (not recommended) build the HTML directly in javascript.

Of course if you're adding data to your table, you'll also want to post that data back to your server to be saved into your database presumably.

相关阅读:
Top