MVC 5与BeginItemCollection动态行 [英] MVC 5 Dynamic Rows with BeginItemCollection

查看:131
本文介绍了MVC 5与BeginItemCollection动态行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一个按钮被点击时添加/删除行的表的最佳方式?我需要ChildClass属性创建(子类是主类/模型中的列表)。行

目前有一个观点(型号为MyMain),它引用使用的RenderPartial的局部视图。

的局部视图显示模型,一类称为MyChild其内MyMain对象列表的属性。

我希望有添加和删除按钮来动态地添加它们持有的局部视图中的行。

因此​​增加MyChild反复名单上更多的行。
这可能吗?或者我应该不会使用局部视图此?

更新code

下面是当前类和看法我与,我一直在努力实现BeginCollectionItem助手的工作,但我发现在这里我想如果声明称创建尽管加载的局部视图空裁判子类的新实例,如果不存在 - 这是为什么被忽略

主要查看

  @using(Html.BeginForm())
{
    <表>
        &所述; TR>
            <第i MyMain首先< /第i
            <第i MyChild首先< /第i
        < / TR>
        &所述; TR>
            &所述; TD>
                @ Html.EditorFor(M = GT; m.First)
            < / TD>
            &所述; TD>
                @if(Model.child!= NULL)
                {
                    的for(int i = 0; I< Model.child.Count;我++)
                    {
                        Html.RenderPartial(MyChildView);
                    }
                }
                其他
                {
                    Html.RenderPartial(MyChildView,新MvcTest.Models.MyChild());
                }
            < / TD>
        < / TR>
        @ Html.ActionLink(添加其他,添加,空,新的{ID =的addItem})
    < /表>
}

管窥

  @model MvcTest.Models.MyChild@using(Html.BeginCollectionItem(myChildren))
{
    Html.EditorFor(M => m.Second);
}

模式

 公共类MyMain
{
    [键]
    公众诠释标识{搞定;组; }
    公共字符串首先{搞定;组; }
    公开名单< MyChild>孩子{搞定;组; }
}公共类MyChild
{
    [键]
    公众诠释标识{搞定;组; }
    公共字符串二{搞定;组; }
}

控制器

 公共类MyMainsController:控制器
{
    // GET:MyMains
    公众的ActionResult MyMainView()
    {
        返回查看();
    }    [HttpPost]
    公众的ActionResult MyMainView(IEnumerable的< MyChild> myChildren)
    {
        返回视图(MyMainView,myChildren);
    }    公众的ViewResult添加()
    {
        返回视图(MyChildView,新MyChild());
    }
}


解决方案

更新答案 - 原来的code是不会真实的动态,但它允许我需要的问题参数范围内所做的一切。

起初,我不能让斯蒂芬的工作中问题的评论BCI建议,从那以后,我和它的辉煌。下面在更新部分中的code,如果你复制粘贴+将工作,但您将需要手动从GIT下载BCI或使用 PM>安装封装BeginCollectionItem 与包管理器控制台在Visual Studio中。

我不得不使用BCI由于复杂性和不前,成就了MVC的不同点一些问题 - <一个href=\"http://stackoverflow.com/questions/32412960/begincollectionitem-partial-within-partial-not-behaving-correctly/32462260#32462260\">here是处理访问 class.property(类型的类).property(类类型).property 了解更多信息。

原来的答复 - 我已经有一个更清晰下面的例子比我的问题并迅速得到了太多混乱

使用两个部分景色,一个是员工的名单,另一个是包含companyemployee的,其中包含公司的目标和员工的对象列表视图模型内设立一个新员工的所有。这样,多个员工可以添加,编辑或删除从列表中。

希望这个答案将帮助任何人在寻找类似的东西,这应该提供足够的code得到它的工作,并至少是推你在正确的方向。

我已经离开了我的背景和初始化器类,因为他们是唯一真正为code首先,如果需要的话我可以添加他们。

感谢所有谁帮助。

模式 - CompanyEmployee是视图模型

 公共类公司
    {
        [键]
        公众诠释ID {搞定;组; }
        [需要]
        公共字符串名称{;组; }
    }
公共类员工
{
    [键]
    公众诠释ID {搞定;组; }
    [需要]
    公共字符串名称{;组; }
    [需要]
    公共字符串JOBTITLE {搞定;组; }
    [需要]
    公共弦数{搞定;组; }
    [需要]
    公共字符串的地址{搞定;组; }
}公共类CompanyEmployee
{
    公众公司的公司{搞定;组; }
    公开名单&LT;员工&GT;员工{搞定;组; }
}

首页

  @model MMV.Models.CompanyEmployee
@ {
    ViewBag.Title =指数;
    布局=〜/查看/共享/ _Layout.cshtml
}&LT; H2&GT;指数&LT; / H&GT;
&LT;&字段集GT;
    &LT;传奇&GT;公司&LT; /传说&GT;
    &LT;表类=表&GT;
        &所述; TR&GT;
            &LT;第i @ Html.LabelFor(M = GT; m.company.name)LT; /第i
        &LT; / TR&GT;
        &所述; TR&GT;
            &LT; TD&GT; @ Html.EditorFor(M = GT; m.company.name)LT; / TD&GT;
        &LT; / TR&GT;
    &LT; /表&gt;
&LT; /字段集&GT;
&LT;&字段集GT;
    &LT;传奇&GT;员工与LT; /传说&GT;        @ {Html.RenderPartial(_ EmployeeList的Model.employees);}&LT; /字段集&GT;
&LT;&字段集GT;
    @ {Html.RenderPartial(_员工,新MMV.Models.Employee());}
&LT; /字段集&GT;
&LT; D​​IV CLASS =表单组&GT;
    &LT; D​​IV CLASS =COL-MD-偏移2 COL-MD-10&GT;
        &LT;输入类型=提交值=提交级=BTN BTN-默认的/&GT;
    &LT; / DIV&GT;
&LT; / DIV&GT;

员工列表PartialView

  @model IEnumerable的&LT; MMV.Models.Employee&GT;
@using(Html.BeginForm(员工))
{
    &LT;表类=表&GT;
        &所述; TR&GT;
            &LT;第i个
                名称
            &LT; /第i
            &LT;第i个
                职称
            &LT; /第i
            &LT;第i个
                数
            &LT; /第i
            &LT;第i个
                地址
            &LT; /第i
            百分位&GT;&LT; /第i
        &LT; / TR&GT;
        @foreach(以型号VAR EMP)
        {
            &所述; TR&GT;
                &所述; TD&GT;
                    @ Html.DisplayFor(modelItem =&GT; emp.name)
                &LT; / TD&GT;
                &所述; TD&GT;
                    @ Html.DisplayFor(modelItem =&GT; emp.jobtitle)
                &LT; / TD&GT;
                &所述; TD&GT;
                    @ Html.DisplayFor(modelItem =&GT; emp.number)
                &LT; / TD&GT;
                &所述; TD&GT;
                    @ Html.DisplayFor(modelItem =&GT; emp.address)
                &LT; / TD&GT;
                &所述; TD&GT;
                    &LT;输入类型=提交formaction =/ Employees/Edit/@emp.id值=编辑/&GT;
                    &LT;输入类型=提交formaction =/ Employees/Delete/@emp.idVALUE =删除/&GT;
                &LT; / TD&GT;
            &LT; / TR&GT;
        }
    &LT; /表&gt;
}

局部视图创建员工

  @model MMV.Models.Employee@using(Html.BeginForm(创建,员工))
{
    &LT;表类=表&GT;        @ Html.ValidationSummary(真,新{@class =TEXT-危险})        &所述; TR&GT;
            &所述; TD&GT;
                @ Html.EditorFor(型号=&GT; model.name)
                @ Html.ValidationMessageFor(型号=&GT; model.name,新{@class =TEXT-危险})
            &LT; / TD&GT;
            &所述; TD&GT;
                @ Html.EditorFor(型号=&GT; model.jobtitle)
                @ Html.ValidationMessageFor(型号=&GT; model.jobtitle)
            &LT; / TD&GT;
            &所述; TD&GT;
                @ Html.EditorFor(型号=&GT; model.number)
                @ Html.ValidationMessageFor(型号=&GT; model.number,新{@class =TEXT-危险})
            &LT; / TD&GT;
            &所述; TD&GT;
                @ Html.EditorFor(型号=&GT; model.address)
                @ Html.ValidationMessageFor(型号=&GT; model.address,新{@class =TEXT-危险})
            &LT; / TD&GT;
        &LT; / TR&GT;
    &LT; /表&gt;
    &LT; D​​IV CLASS =表单组&GT;
        &LT; D​​IV CLASS =COL-MD-偏移2 COL-MD-10&GT;
            &LT;输入类型=提交值=创建类=BTN BTN-默认的/&GT;
        &LT; / DIV&GT;
    &LT; / DIV&GT;
}

控制器 - 我使用了多个,但你可以把他们都在一个

 公共类CompanyEmployeeController:控制器
    {
        私人MyContext DB =新MyContext();        // GET:CompanyEmployee
        公众的ActionResult指数()
        {
            VAR newCompanyEmployee =新CompanyEmployee();
            newCompanyEmployee.employees = db.EmployeeContext.ToList();
            返回查看(newCompanyEmployee);
        }
[HttpPost,ActionName(删除)]
        公众的ActionResult DeleteConfirmed(INT ID)
        {
            员工员工= db.EmployeeContext.Find(ID);
            db.EmployeeContext.Remove(员工);
            db.SaveChanges();
            返回RedirectToAction(指数,CompanyEmployee);
        }[HttpPost]
        公众的ActionResult创建([绑定(包括=ID,姓名,JOBTITLE,号码,地址)员工员工)
        {
            如果(ModelState.IsValid)
            {
                db.EmployeeContext.Add(员工);
                db.SaveChanges();
                返回RedirectToAction(指数,CompanyEmployee);
            }            返回查看(员工);
        }
}

更新code - 使用BeginCollectionItem - 动态添加/删除

学生偏

  @model有用的code.Models.Person
&LT; D​​IV CLASS =editorRow&GT;
    @using(Html.BeginCollectionItem(学生))
    {
        &LT; D​​IV CLASS =UI网-C UI响应&GT;
            &LT; D​​IV CLASS =UI-块一个&GT;
                &LT;跨度&GT;
                    @ Html.TextBoxFor(M = GT; m.firstName)
                &LT; / SPAN&GT;
            &LT; / DIV&GT;
            &LT; D​​IV CLASS =UI块-B&GT;
                &LT;跨度&GT;
                    @ Html.TextBoxFor(M = GT; m.lastName)
                &LT; / SPAN&GT;
            &LT; / DIV&GT;
            &LT; D​​IV CLASS =UI块-C&GT;
                &LT;跨度&GT;
                    &LT;跨度类=dltBtn&GT;
                        &所述; A HREF =#类=deleteRow&X的催化剂&下; / A&GT;
                    &LT; / SPAN&GT;
                &LT; / SPAN&GT;
            &LT; / DIV&GT;
        &LT; / DIV&GT;
    }
&LT; / DIV&GT;

教师部分

  @model有用的code.Models.Person
&LT; D​​IV CLASS =editorRow&GT;
    @using(Html.BeginCollectionItem(教师))
    {
        &LT; D​​IV CLASS =UI网-C UI响应&GT;
            &LT; D​​IV CLASS =UI-块一个&GT;
                &LT;跨度&GT;
                    @ Html.TextBoxFor(M = GT; m.firstName)
                &LT; / SPAN&GT;
            &LT; / DIV&GT;
            &LT; D​​IV CLASS =UI块-B&GT;
                &LT;跨度&GT;
                    @ Html.TextBoxFor(M = GT; m.lastName)
                &LT; / SPAN&GT;
            &LT; / DIV&GT;
            &LT; D​​IV CLASS =UI块-C&GT;
                &LT;跨度&GT;
                    &LT;跨度类=dltBtn&GT;
                        &所述; A HREF =#类=deleteRow&X的催化剂&下; / A&GT;
                    &LT; / SPAN&GT;
                &LT; / SPAN&GT;
            &LT; / DIV&GT;
        &LT; / DIV&GT;
    }
&LT; / DIV&GT;
注册控制器公众的ActionResult指数()
{
    VAR寄存器=新注册
    {
        学生=新的List&LT;&人GT;
        {
            新的Person {的firstName =,姓氏=}
        },
        教师=新的List&LT;&人GT;
        {
            新的Person {lastName的=,名字=}
        }
    };    返回查看(寄存器);
}

和注册角色模型

 公共类注册
{
    公众诠释ID {搞定;组; }
    公开名单&LT;&人GT;教师{搞定;组; }
    公开名单&LT;&人GT;学生{搞定;组; }
}公共类Person
{
    公众诠释ID {搞定;组; }
    公共字符串的firstName {搞定;组; }
    公共字符串的lastName {搞定;组; }
}

指数

  @ {
    布局=〜/查看/共享/ _Layout.cshtml
}
@Model有用的code.Models.Register
&LT; D​​IV ID =studentList&GT;
@using(Html.BeginForm())
{
    &LT; D​​IV ID =editorRowsStudents&GT;
        @foreach(在Model.students VAR项)
        {
            @ Html.Partial(StudentView项)
        }
    &LT; / DIV&GT;
    @ Html.ActionLink(添加,StudentManager,空,新的{ID =addItemStudents,@class =按钮});
}
&LT; / DIV&GT;&LT; D​​IV ID =teacherList&GT;
@using(Html.BeginForm())
{
    &LT; D​​IV ID =editorRowsTeachers&GT;
        @foreach(在Model.teachers VAR项)
        {
            @ Html.Partial(TeacherView项)
        }
    &LT; / DIV&GT;
    @ Html.ActionLink(添加,TeacherManager,空,新的{ID =addItemTeachers,@class =按钮});
}
&LT; / DIV&GT;
@section脚本{
    &LT;脚本类型=文/ JavaScript的&GT;
    $(函数(){
        $('#addItemStudents')。在('点击',功能(){
            $阿贾克斯({
                网址:'@ Url.Action(StudentManager)',
                    缓存:假的,
                    成功:功能(HTML){$(#editorRowsStudents)追加(HTML)。 }
                });
                返回false;
            });
            $('#editorRowsStudents')。在('点击','.deleteRow',函数(){
                $(本).closest('editorRow。')删除()。
            });
            $('#addItemTeachers')。在('点击',功能(){
                $阿贾克斯({
                    网址:'@ Url.Action(TeacherManager)',
                    缓存:假的,
                    成功:功能(HTML){$(#editorRowsTeachers)追加(HTML)。 }
                });
                返回false;
            });
            $('#editorRowsTeachers')。在('点击','.deleteRow',函数(){
                $(本).closest('editorRow。')删除()。
            });
        });
    &LT; / SCRIPT&GT;
}

What is the best way to add/delete rows to a table when a button is clicked? I need rows created from ChildClass properties (child class is a list within the main class/model).

Currently have a View (model is MyMain) which references a Partial View using RenderPartial.

The partial view displays the properties of the model, a class called MyChild which is an object list within MyMain.

I want to have add and delete buttons to dynamically add the rows which are held within the partial view.

So adding MyChild repeatedly for more rows on the list. Is this possible? Or should I not be using partial views for this?

Updated Code

Below are the current classes and views I'm working with, I've been trying to implement the BeginCollectionItem helper but I'm getting null ref where I'm trying to load the partial view despite the if statement saying to create a new instance of the child class if doesn't exist - why is this being ignored?

Main View

    @using (Html.BeginForm())
{
    <table>
        <tr>
            <th>MyMain First</th>
            <th>MyChild First</th>
        </tr>
        <tr>
            <td>
                @Html.EditorFor(m => m.First)
            </td>
            <td>
                @if (Model.child != null)
                {
                    for (int i = 0; i < Model.child.Count; i++)
                    {
                        Html.RenderPartial("MyChildView");
                    }
                }        
                else
                {
                    Html.RenderPartial("MyChildView", new MvcTest.Models.MyChild());
                }       
            </td>
        </tr>
        @Html.ActionLink("Add another", "Add", null, new { id = "addItem" })
    </table>
}

Partial View

@model MvcTest.Models.MyChild

@using (Html.BeginCollectionItem("myChildren"))
{
    Html.EditorFor(m => m.Second);
}

Models

public class MyMain
{
    [Key]
    public int Id { get; set; }
    public string First { get; set; }
    public List<MyChild> child { get; set; }
}

public class MyChild
{
    [Key]
    public int Id { get; set; }
    public string Second { get; set; }
}

Controller

public class MyMainsController : Controller
{
    // GET: MyMains
    public ActionResult MyMainView()
    {
        return View();
    }

    [HttpPost]
    public ActionResult MyMainView(IEnumerable<MyChild> myChildren)
    {
        return View("MyMainView", myChildren);
    }

    public ViewResult Add()
    {
        return View("MyChildView", new MyChild());
    }
}

解决方案

Updated Answer - The original code is NOT true to 'dynamic', however it allows for everything I needed to do within the question parameters.

Initially, I couldn't get Stephen's BCI suggestion in the question comments working, since then I have and it's brilliant. The code below in the updated section will work if you copy + paste, but you will need to either manually download BCI from GIT or use PM> Install-Package BeginCollectionItem with Package Manager Console in Visual Studio.

I had some issue with various points using BCI due to the complexity and not having done MVC before - here is more information on dealing with accessing class.property(type class).property(type class).property.

Original answer - I've gone with a more clear example below than in my question which quickly got too confusing.

Using two partial views, one for the list of employees and another for the creation of a new employee all contained within the viewmodel of companyemployee which contains an object of company and a list of employee objects. This way multiple employees can be added, edited or deleted from the list.

Hopefully this answer will help anyone looking for something similar, this should provide enough code to get it working and at the very least push you in the right direction.

I've left out my context and initialiser classes as they're only true to code first, if needed I can add them.

Thanks to all who helped.

Models - CompanyEmployee being the view model

public class Company
    {
        [Key]
        public int id { get; set; }
        [Required]
        public string name { get; set; }
    }
public class Employee
{
    [Key]
    public int id { get; set; }
    [Required]
    public string name { get; set; }
    [Required]
    public string jobtitle { get; set; }
    [Required]
    public string number { get; set; }
    [Required]
    public string address { get; set; }
}

public class CompanyEmployee
{
    public Company company { get; set; }
    public List<Employee> employees { get; set; }
}

Index

@model MMV.Models.CompanyEmployee
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>
<fieldset>
    <legend>Company</legend>
    <table class="table">
        <tr>
            <th>@Html.LabelFor(m => m.company.name)</th>
        </tr>
        <tr>
            <td>@Html.EditorFor(m => m.company.name)</td>
        </tr>
    </table>
</fieldset>
<fieldset>
    <legend>Employees</legend>

        @{Html.RenderPartial("_employeeList", Model.employees);}

</fieldset>
<fieldset>
    @{Html.RenderPartial("_employee", new MMV.Models.Employee());}
</fieldset>
<div class="form-group">
    <div class="col-md-offset-2 col-md-10">
        <input type="submit" value="Submit" class="btn btn-default" />
    </div>
</div>

PartialView of List of Employees

@model IEnumerable<MMV.Models.Employee>
@using (Html.BeginForm("Employees"))
{
    <table class="table">
        <tr>
            <th>
                Name
            </th>
            <th>
                Job Title
            </th>
            <th>
                Number
            </th>
            <th>
                Address
            </th>
            <th></th>
        </tr>
        @foreach (var emp in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => emp.name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => emp.jobtitle)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => emp.number)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => emp.address)
                </td>
                <td>
                    <input type="submit" formaction="/Employees/Edit/@emp.id" value="Edit"/>
                    <input type="submit"formaction="/Employees/Delete/@emp.id" value="Remove"/>
                </td>
            </tr>
        }
    </table>
}

Partial View Create Employee

@model MMV.Models.Employee

@using (Html.BeginForm("Create","Employees"))
{
    <table class="table">

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <tr>
            <td>
                @Html.EditorFor(model => model.name)
                @Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
            </td>
            <td>
                @Html.EditorFor(model => model.jobtitle)
                @Html.ValidationMessageFor(model => model.jobtitle)
            </td>
            <td>
                @Html.EditorFor(model => model.number)
                @Html.ValidationMessageFor(model => model.number, "", new { @class = "text-danger" })
            </td>
            <td>
                @Html.EditorFor(model => model.address)
                @Html.ValidationMessageFor(model => model.address, "", new { @class = "text-danger" })
            </td>
        </tr>
    </table>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>
}

Controller - I used multiple but you can put them all in one

public class CompanyEmployeeController : Controller
    {
        private MyContext db = new MyContext();

        // GET: CompanyEmployee
        public ActionResult Index()
        {
            var newCompanyEmployee = new CompanyEmployee();
            newCompanyEmployee.employees = db.EmployeeContext.ToList();
            return View(newCompanyEmployee);
        }
[HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Employee employee = db.EmployeeContext.Find(id);
            db.EmployeeContext.Remove(employee);
            db.SaveChanges();
            return RedirectToAction("Index", "CompanyEmployee");
        }

[HttpPost]
        public ActionResult Create([Bind(Include = "id,name,jobtitle,number,address")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeContext.Add(employee);
                db.SaveChanges();
                return RedirectToAction("Index", "CompanyEmployee");
            }

            return View(employee);
        }
}

Updated Code - using BeginCollectionItem - dynamic add/delete

Student Partial

@model UsefulCode.Models.Person
<div class="editorRow">
    @using (Html.BeginCollectionItem("students"))
    {
        <div class="ui-grid-c ui-responsive">
            <div class="ui-block-a">
                <span>
                    @Html.TextBoxFor(m => m.firstName)
                </span>
            </div>
            <div class="ui-block-b">
                <span>
                    @Html.TextBoxFor(m => m.lastName)
                </span>
            </div>
            <div class="ui-block-c">
                <span>
                    <span class="dltBtn">
                        <a href="#" class="deleteRow">X</a>
                    </span>
                </span>
            </div>
        </div>
    }
</div>

Teacher Partial

@model UsefulCode.Models.Person
<div class="editorRow">
    @using (Html.BeginCollectionItem("teachers"))
    {
        <div class="ui-grid-c ui-responsive">
            <div class="ui-block-a">
                <span>
                    @Html.TextBoxFor(m => m.firstName)
                </span>
            </div>
            <div class="ui-block-b">
                <span>
                    @Html.TextBoxFor(m => m.lastName)
                </span>
            </div>
            <div class="ui-block-c">
                <span>
                    <span class="dltBtn">
                        <a href="#" class="deleteRow">X</a>
                    </span>
                </span>
            </div>
        </div>
    }
</div>
Register Controller

public ActionResult Index()
{
    var register = new Register
    {
        students = new List<Person>
        {
            new Person { firstName = "", lastName = "" }
        },
        teachers = new List<Person> 
        {
            new Person { lastName = "", firstName = "" }
        }
    };

    return View(register);
}

Register and Person Model

public class Register
{
    public int id { get; set; }
    public List<Person> teachers { get; set; }
    public List<Person> students { get; set; }
}

public class Person
{
    public int id { get; set; }
    public string firstName { get; set; }
    public string lastName { get; set; }
}

Index

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model UsefulCode.Models.Register
<div id="studentList">
@using (Html.BeginForm())
{
    <div id="editorRowsStudents">
        @foreach (var item in Model.students)
        {
            @Html.Partial("StudentView", item)
        }
    </div>
    @Html.ActionLink("Add", "StudentManager", null, new { id = "addItemStudents", @class = "button" });
}
</div>

<div id="teacherList">
@using (Html.BeginForm())
{
    <div id="editorRowsTeachers">
        @foreach (var item in Model.teachers)
        {
            @Html.Partial("TeacherView", item)
        }
    </div>
    @Html.ActionLink("Add", "TeacherManager", null, new { id = "addItemTeachers", @class = "button" });
}
</div>


@section scripts {
    <script type="text/javascript">
    $(function () {
        $('#addItemStudents').on('click', function () {
            $.ajax({
                url: '@Url.Action("StudentManager")',
                    cache: false,
                    success: function (html) { $("#editorRowsStudents").append(html); }
                });
                return false;
            });
            $('#editorRowsStudents').on('click', '.deleteRow', function () {
                $(this).closest('.editorRow').remove();
            });
            $('#addItemTeachers').on('click', function () {
                $.ajax({
                    url: '@Url.Action("TeacherManager")',
                    cache: false,
                    success: function (html) { $("#editorRowsTeachers").append(html); }
                });
                return false;
            });
            $('#editorRowsTeachers').on('click', '.deleteRow', function () {
                $(this).closest('.editorRow').remove();
            });
        });
    </script>
}

这篇关于MVC 5与BeginItemCollection动态行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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