mvc editorfor listitem从jquery添加新功能 [英] Mvc editorfor listitem add new from jquery

查看:60
本文介绍了mvc editorfor listitem从jquery添加新功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想知道如何在MVC4的集合中添加新的'row'

我的model包含一个IList<>。

这个列表循环,为每个记录调用一个EditorFor。

一切正常(包括回发),除了添加一个新的记录。



我想用javascript收集新的EditorFor的html并将其添加到我的桌面。



花费最后2个小时google'ing,但似乎无法找到答案。



希望有人有个主意:)



Hi All,

I am trying to figure out how to add a new 'row' in a collection in MVC4
My model contains a IList<>.
This list is looped, for every record a EditorFor is called.
Everything works fine (including posting back), except adding a new record.

I would like to collect the html of a new EditorFor with javascript and add it to my table.

Spend the last 2 hours google'ing, but cant seem to find the answer.

hope somebody has an idea :)

Edit.cshtml
@using (Html.BeginForm()){
                        @for (int i = 0; i < Model.Regels_.Count; i++) {
                            @Html.EditorFor(m => Model.Regels_[i])
                        }



Ed itorTemplate为Regel_项目。


EditorTemplate for "Regel_" item.

<tr>
    <td>
        @Html.EditorFor(m => Model.Aantal)
    </td>
    
....etc







$('#CmdAddNewRegel').click(function () {
    $.ajax({
        url: '@Url.Action("EditorTemplate??")',
        cache: false,
        success: function (html) {
            $("#TableRegels").append(html);
        }
    });





我尝试了什么:



我是在没有editorTemplate的情况下开始的。

然后我尝试将我的'row'视图放在partialView中。

这个工作,除了回发(部分视图没有在字段名称中添加[I]。) br />
编辑器似乎要走了,只是无法想出这最后一部分。



What I have tried:

I've started out without the editorTemplate.
Then I tried putting my 'row' view in a partialView.
this worked, except posting back (the partial view didn't add the [I] in the field names.
EditorFor seems the way to go, just can't figure this last part out.

推荐答案

' #CmdAddNewRegel')。click(function(){
('#CmdAddNewRegel').click(function () {


。 ajax({
url:' @ Url.Action(EditorTemplate ??)'
cache: false
success:function(html){
.ajax({ url: '@Url.Action("EditorTemplate??")', cache: false, success: function (html) {


#TableRegels)。append(html);
}
});
("#TableRegels").append(html); } });





我的尝试:



我没有使用editorTemplate就开始了。

然后我尝试将我的'row'视图放在partialView中。

这个工作,除了回发(部分视图没有在字段名称中添加[I]。

编辑器似乎要走了,只是无法想出这最后一部分。



What I have tried:

I've started out without the editorTemplate.
Then I tried putting my 'row' view in a partialView.
this worked, except posting back (the partial view didn't add the [I] in the field names.
EditorFor seems the way to go, just can't figure this last part out.


这篇关于mvc editorfor listitem从jquery添加新功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆