微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

大家好,我该如何将Ajax列表发布到MVC

如何解决大家好,我该如何将Ajax列表发布到MVC

    [HttpPost]
    public ActionResult check(List<tbl_checklist> chk)
    {

        db.tbl_checklist.AddRange(chk);
        db.SaveChanges();

      return RedirectToAction("den_list","denetim");
    }

如您所见,我想从视图中列出数据。但是我不能

解决方法

这是我使用的方法,它使用剑道,但不必:https://onallthingsweb.wordpress.com/2016/06/27/asp-net-mvc-and-client-side-lists-with-kendo/

本质上,以该模型为例:

public  class SystemTestModel
{
   public List Entities { get; set; }
}

public class SystemListEntity
{
   public string Name { get; set; }
   public string Value { get; set; }
   public bool IsDeleted { get; set; }
}

您可以像这样绑定到Entities属性:

for (var i = 0; i < Model.Entities.Count; i++)
{
   <tr>
      <td>
          
          <input type="hidden" name="@Html.NameFor(m => m.Entities[i].IsDeleted)" value="@Boolean.FalseString" />
      </td>
      <td>
          <input type="text" value="#= Value #" name="@Html.NameFor(m => m.Entities[i].Value)" />
      </td>
   </tr>
}

将此表单发回服务器后,您的操作方法将根据需要接收所有数据:

public ActionResult Index(SystemTextModel model)
{
    foreach (var entity in model.Entities)
    {
        //the data in the UI is passed back to the server
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。