【问题标题】:Asp.net Mvc Form & KendoView Grid Save ToghterAsp.net Mvc Form 和 Kendo Vue Grid 一起保存
【发布时间】:2013-12-13 10:30:45
【问题描述】:

我在 sql server 中有 2 个不同的表,表 1 是 asp.net mvc 表单的一部分,第二个表是 kendo 网格的一部分,如何通过单个按钮将两个表保存一次。

 ****Table 1 is part of asp.net mvc form as following****

 @using (Html.BeginForm())
 {
 @Html.TextBoxFor(m => m.CustomerID)
 }

 ****Table 2 is part of Kendo Grid****
 @(Html.Kendo().Grid<Accounting.DAL.InvoiceDetail>()
 .Name("Grid")
 .Columns(columns =>
 {

  }
  )

【问题讨论】:

    标签: asp.net-mvc grid kendo-ui


    【解决方案1】:

    我认为您是 MVC 的新手。在 MVC 中,每个视图代表一个模型(领域逻辑类)。

    @using model Applciaton.Models.SomeViewmodel
    

    //这将创建一个表单标签。您可以在此处提及您的目标控制器操作。

    @using (Html.BeginForm()) 
    

    // 带有action和post属性的表单标签。

    @using(Html.BeginForm('action','controller',FormMethod.Post,new {id="formID"}))
    {
      //your tables and kendo grid should be inside this form tag so you can post them to server.
      <input type="submit" value="save"/> //This will submit the form to controller action
    }
    

    所以当您的视图向服务器(控制器)提交数据时,您可以使用模型接收它。

     [HttpPost] // Post Attribute.
     public ActionResult action(SomeViewmodel obj)//Viewmodel object from view.
     {
         //you have your kendo grid data posted from view.
    
         // you also have other table data and all the data you specified in model will be here.
    
         //Save it to db from model. call the repository from here and pass relevent data.
    
     }
    

    【讨论】:

    • 问题是,我有 2 个控制器,InvoiceController & InvoiceDetailController & 当然还有 2 个 Models 类。 InvoiceController 生成外键,并保存到第二个控制器 InvoiceDetailController .... InvoiceController 专用于 Html.begin.form & ...InvoiceDetailController 专用于 KendoGrid
    • 你不能像那样扔控制器。 View 代表一个模型,控制器在模型和视图之间工作。
    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 2014-12-05
    • 1970-01-01
    • 2016-02-02
    • 2023-03-16
    • 2019-05-02
    • 2020-11-09
    • 1970-01-01
    相关资源
    最近更新 更多