查看值不会返回到控制器操作

任何人都可以告诉我的看法有什么问题吗? 我的模型值在我的视图中正确显示,但它不返回到控制器操作。 public ActionResult DeleteConfirmed(ClientModel contacts)我的ClientModel返回null。

视图:

@model ContactManager.Models.ClientModel

@{
    ViewBag.Title = "Delete Information";
}

<h2>Delete Information</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>Details</legend>

    <div class="display-label">ID</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.CanaClie0012.Client00130012)
    </div>

    <div class="display-label">Name</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Clientes0013.Nombre0013)
    </div>

    <div class="display-label">Contact Number</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.CanaClie0012.Direcc0012)
    </div>

    <div class="display-label">Country</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.CanaClie0012.F1Pais00200012)
    </div>

</fieldset>
@using (Html.BeginForm()) {
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
}

控制器操作:

[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(ClientModel contacts)
        {
            contacts.Clientes0013.Client0013 = contacts.CanaClie0012.Client00130012;
            contacts.Clientes0013.F1Pais00200013 = contacts.CanaClie0012.F1Pais00200012;
            Clientes0013 clientes0013 = db.Clientes0013.Find(contacts.Clientes0013.Client0013, contacts.Clientes0013.F1Pais00200013);
            db.Clientes0013.Remove(clientes0013);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

1.将助手保持在下面的窗体中。

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, null))
{
    @Html.DisplayFor(i => i.PropertyName);
    <input type="submit" name="Submit" value="Submit" />
}

2.为了在Post Action Method中提交表单并发送模型,您必须与每个DisplayFor Helper一起使用一个隐藏字段。

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, null))
{
    @Html.HiddenFor(i => i.PropertyName);
    @Html.DisplayFor(i => i.PropertyName);
    <input type="submit" name="Submit" value="Submit" />
}

3.当View如下所示时,您将无法在Post Action Method中看到Model值。

@Html.HiddenFor(i => i.PropertyName);
@Html.DisplayFor(i => i.PropertyName);
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, null))
{

    <input type="submit" name="Submit" value="Submit" />
}

这是因为您正在为所有属性使用DisplayForDisplayFor不会在POST中发送任何内容,它不会创建输入。 您可以将@Html.HiddenFor(model => model.CanaClie0012.Client00130012)等添加到您的每个属性中,以便您的视图发回任何内容。

链接地址: http://www.djcxy.com/p/53963.html

上一篇: View values not returned to the controller action

下一篇: C# MVC4 changed view property not changing data on view HTML page