Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET MVC保存按钮加载但不工作_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# ASP.NET MVC保存按钮加载但不工作

C# ASP.NET MVC保存按钮加载但不工作,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我在索引页上的.NET应用程序中实现了一个保存按钮。当我单击它时,它会加载,但不会保存任何内容。我只是将索引页用于复选框。如果我取消选中某个内容并保存它,它会保存,但也会取消选中该行中的所有其他内容。当我试图检查某些东西时,什么也没有发生。以下是我正在使用的代码: Index.cshtml @using (Html.BeginForm("save", "drnos")) { <input type="submit" value="Save" /> } 以下是整个HTML文件

我在索引页上的.NET应用程序中实现了一个保存按钮。当我单击它时,它会加载,但不会保存任何内容。我只是将索引页用于复选框。如果我取消选中某个内容并保存它,它会保存,但也会取消选中该行中的所有其他内容。当我试图检查某些东西时,什么也没有发生。以下是我正在使用的代码:

Index.cshtml

@using (Html.BeginForm("save", "drnos"))
{
    <input type="submit" value="Save" />
}
以下是整个HTML文件:

@model PagedList.IPagedList<drnosv6.Models.Doctor>
@using PagedList.Mvc;

<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />


@{
    ViewBag.Title = "Index";
}

<h2>Doctors</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm()) //insert the search bar
{
    <p>
        Find by First Name, Last Name, or RVH ID: @Html.TextBox("SearchString")

        <input type="submit" value="Search" />

    </p>
}

@using (Html.BeginForm("save", "drnos"))
{
    <input type="submit" value="Save" />
}

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('tr:even').addClass('alt-row-class');
    });

</script>

<p>    
</p>

<p>Click on a column header to sort by that column</p>

<table>
    <tr>
        <th>
            @Html.ActionLink("RVH ID", "Index", new { sortOrder = ViewBag.IDSortParm })
        </th>

        <th>
            @Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.LastSortParm })
        </th>
        <th>
            @Html.ActionLink("First Name", "Index", new { sortOrder = ViewBag.FirstSortParm })
        </th>
        <th>
            Middle Initial
        </th>
        <th>
            Degree
        </th>
        <th>
            Group
        </th>
        <th>
            Adm Priv
        </th>

        <th>
            @Html.ActionLink("QCPR", "Index", new { sortOrder = ViewBag.QCPRSortParm })

        </th>
        <th>
            @Html.ActionLink("Keane", "Index", new { sortOrder = ViewBag.KeaneSortParm })
        </th>
        <th>
            @Html.ActionLink("Orsos", "Index", new { sortOrder = ViewBag.OrsosSortParm })
        </th>
        <th>
            @Html.ActionLink("Soft", "Index", new { sortOrder = ViewBag.SoftSortParm })
        </th>
        <th>
            @Html.ActionLink("3M", "Index", new { sortOrder = ViewBag.threeMSortParm })
        </th>

        <th></th>
    </tr>

    @foreach (var item in Model)
    { 
        using (Html.BeginForm("Save", "Doctor", FormMethod.Post))

    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.RVH_ID_)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.Last_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.First_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Middle_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Degree1)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Group)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.AdmPriv)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QCPR)
            </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>
                @Html.EditorFor(modelItem => item.Soft)
                @Html.ValidationMessageFor(modelItem => item.Soft)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.C3M)
            </td>

            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.RVH_ID_ })
                @Html.ActionLink("Details", "Details", new { id = item.RVH_ID_ })

            </td>
        </tr>
    }
    }

</table>

<p>
    <input type="submit" value="Save" />
</p>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

@Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
@model PagedList.IPagedList
@使用PagedList.Mvc;
@{
ViewBag.Title=“Index”;
}
医生

@ActionLink(“新建”、“创建”)

@使用(Html.BeginForm())//插入搜索栏 { 按名字、姓氏或RVH ID查找:@Html.TextBox(“搜索字符串”)

} @使用(Html.BeginForm(“save”,“drnos”)) { } $(文档).ready(函数(){ $('tr:even').addClass('alt-row-class'); });

单击列标题以按该列排序

@ActionLink(“RVH ID”,“Index”,new{sortOrder=ViewBag.IDSortParm}) @ActionLink(“姓氏”,“索引”,new{sortOrder=ViewBag.LastSortParm}) @ActionLink(“名字”,“索引”,新的{sortOrder=ViewBag.FirstSortParm}) 中间字首 度 团体 私人行政 @ActionLink(“QCPR”,“Index”,new{sortOrder=ViewBag.QCPRSortParm}) @ActionLink(“基恩”,“索引”,新的{sortOrder=ViewBag.KeaneSortParm}) @ActionLink(“Orsos”,“Index”,new{sortOrder=ViewBag.orssortparm}) @ActionLink(“Soft”,“Index”,new{sortOrder=ViewBag.SoftSortParm}) @ActionLink(“3M”,“Index”,new{sortOrder=ViewBag.threeMSortParm}) @foreach(模型中的var项目) { 使用(Html.BeginForm(“保存”、“医生”、FormMethod.Post)) { @DisplayFor(modelItem=>item.RVH\u ID) @DisplayFor(modelItem=>item.Last_Name) @DisplayFor(modelItem=>item.First\u Name) @DisplayFor(modelItem=>item.Middle\u名称) @DisplayFor(modelItem=>item.Degree1) @DisplayFor(modelItem=>item.Group) @DisplayFor(modeleItem=>item.AdmPriv) @DisplayFor(modeleItem=>item.QCPR) @EditorFor(modeleItem=>item.Keane) @Html.ValidationMessageFor(modelItem=>item.Keane) @EditorFor(modeleItem=>item.Orsos) @Html.ValidationMessageFor(modelItem=>item.Orsos) @EditorFor(modeleItem=>item.Soft) @Html.ValidationMessageFor(modelItem=>item.Soft) @DisplayFor(modeleItem=>item.C3M) @ActionLink(“编辑”,“编辑”,新的{id=item.RVH_id}) @ActionLink(“详细信息”,“详细信息”,新的{id=item.RVH_id}) } }


@Model.PageCount的@页(Model.PageCountUrl.Action(“Index”,new{page,sortOrder=ViewBag.CurrentSort,currentFilter=ViewBag.currentFilter}))
提交表单时,仅提交该表单中声明的输入。表单中只有“提交”按钮,因此没有其他字段可以填写您的
Doctor
结构。您需要将“保存”按钮与所有其他字段放在同一表单上。

您的BeginForm或ActionLink必须指向ActionResult Edit。

当我单击它时,它将加载
调用
编辑
操作是什么意思?如果是,您能否验证是否使用断点调用了
SaveChanges
如果我取消选中某项
你在说什么?我在你的表格中没有看到任何复选框。如果元素与问题相关,则也应包含它们。您的输入字段必须在表单中,否则它们不会发布。@Dimi这是HTML文件:我必须在Dropbox下注册才能查看您的HTML吗?:)@迪米,我不这么认为!哦,谢谢你指出这一点。我粘贴了错误的保存函数。我编辑了它。
[HttpPost]
public ActionResult save(Doctor doc)
{
    System.Diagnostics.Debug.WriteLine("Save Called");
    db.Entry(doc).State = EntityState.Modified;
    db.SaveChanges();
    return RedirectToAction("Index");  
}
@model PagedList.IPagedList<drnosv6.Models.Doctor>
@using PagedList.Mvc;

<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />


@{
    ViewBag.Title = "Index";
}

<h2>Doctors</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm()) //insert the search bar
{
    <p>
        Find by First Name, Last Name, or RVH ID: @Html.TextBox("SearchString")

        <input type="submit" value="Search" />

    </p>
}

@using (Html.BeginForm("save", "drnos"))
{
    <input type="submit" value="Save" />
}

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('tr:even').addClass('alt-row-class');
    });

</script>

<p>    
</p>

<p>Click on a column header to sort by that column</p>

<table>
    <tr>
        <th>
            @Html.ActionLink("RVH ID", "Index", new { sortOrder = ViewBag.IDSortParm })
        </th>

        <th>
            @Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.LastSortParm })
        </th>
        <th>
            @Html.ActionLink("First Name", "Index", new { sortOrder = ViewBag.FirstSortParm })
        </th>
        <th>
            Middle Initial
        </th>
        <th>
            Degree
        </th>
        <th>
            Group
        </th>
        <th>
            Adm Priv
        </th>

        <th>
            @Html.ActionLink("QCPR", "Index", new { sortOrder = ViewBag.QCPRSortParm })

        </th>
        <th>
            @Html.ActionLink("Keane", "Index", new { sortOrder = ViewBag.KeaneSortParm })
        </th>
        <th>
            @Html.ActionLink("Orsos", "Index", new { sortOrder = ViewBag.OrsosSortParm })
        </th>
        <th>
            @Html.ActionLink("Soft", "Index", new { sortOrder = ViewBag.SoftSortParm })
        </th>
        <th>
            @Html.ActionLink("3M", "Index", new { sortOrder = ViewBag.threeMSortParm })
        </th>

        <th></th>
    </tr>

    @foreach (var item in Model)
    { 
        using (Html.BeginForm("Save", "Doctor", FormMethod.Post))

    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.RVH_ID_)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.Last_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.First_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Middle_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Degree1)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Group)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.AdmPriv)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QCPR)
            </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>
                @Html.EditorFor(modelItem => item.Soft)
                @Html.ValidationMessageFor(modelItem => item.Soft)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.C3M)
            </td>

            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.RVH_ID_ })
                @Html.ActionLink("Details", "Details", new { id = item.RVH_ID_ })

            </td>
        </tr>
    }
    }

</table>

<p>
    <input type="submit" value="Save" />
</p>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

@Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))