如何在ASP.NET中的索引页面上创建表单? [英] How do I create a form on an Index page in ASP.NET?

查看:69
本文介绍了如何在ASP.NET中的索引页面上创建表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在Visual Studio中构建一个ASP.NET MVC应用程序。我是新手,并且很难在索引页面上构建表单。我希望人们能够选中一个框并点击保存按钮,而不必转到单独的编辑页面。字段Keane和orsos是可检查字段。我编写了函数并调用了save方法并刷新了页面,但我保存的内容都没有保存。任何帮助将不胜感激!



Index.cshtml

Hello, I am building an ASP.NET MVC application in Visual Studio. I am new to this and am having a hard time building a form right onto the index page. I want people to be able to check a box and hit the save button instead of having to go to a separate edit page. The fields "Keane" and "orsos" are the checkable fields. I have written the function and the save method is called and the page refreshes, but nothing I change is saved. Any help would be appreciated!

Index.cshtml

@using (Html.BeginForm("save", "drnos"))
{
    {
<input type="submit" value="Save" />
<table>
    <tr>
<th>
     @Html.ActionLink("RVH ID", "Index", new { sortOrder = ViewBag.IDSortParm })
</th>
<th>
    @Html.ActionLink("Keane", "Index", new { sortOrder = ViewBag.KeaneSortParm })
</th>
<th>
    @Html.ActionLink("Orsos", "Index", new { sortOrder = ViewBag.OrsosSortParm })
</th>

 @foreach (var item in Model)
    {
<td>
        @Html.DisplayFor(modelItem => item.RVH_ID_)
</td>
<td>
        @Html.EditorFor(modelItem => item.Keane)
        @Html.ValidationMessageFor(modelItem => item.Keane)
</td>
<td>
       @Html.EditorFor(modelItem => item.Orsos)
       @Html.ValidationMessageFor(modelItem => item.Orsos)
</td>
 </td>
   </tr>
    }
</table>
}
}





drnosController



drnosController

[HttpPost]
        public ActionResult Save(Doctor doc)
        {
             System.Diagnostics.Debug.WriteLine("Save Called");

             db.Entry(doc).State = EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");  
        }

推荐答案

您的模型显然是一个list \收集的东西,但您的保存操作只需要一个项目,所以你提交的数据(一系列的东西)与动作所期望的模型不符(一件事)。



谷歌的类似 asp.net mvc列表作为模型用于处理列表作为模型的示例。



http://www.binaryintellect.net/articles/b1e0b153-47f4-4b29-8583-958aa22d9284.aspx [ ^ ]
Your Model is obviously a list\collection of something, but your save action only takes a single item, so the data you are submitting (a list of things) doesn't match the model the action is expecting (a single thing).

Google for something like "asp.net mvc list as model" for examples on handling lists as models.

http://www.binaryintellect.net/articles/b1e0b153-47f4-4b29-8583-958aa22d9284.aspx[^]


这篇关于如何在ASP.NET中的索引页面上创建表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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