【发布时间】:2016-02-14 19:01:35
【问题描述】:
@model CommonLayer.ORDER
@{
ViewBag.Title = "Update";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h4>Update Order Status</h4>
<br />
@if (Model.OrderStatus != "Shipped")
{
using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.UserId)
<div class="form-group">
@Html.LabelFor(model => model.OrderId, htmlAttributes: new { @style = "font-size:medium", @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.OrderId, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OrderStatus, htmlAttributes: new { @style = "font-size:medium", @class = "control-label col-md-2" })
<div class="col-md-10">
<select class="form-control" name="OrderStatus">
<option value="Pending" id="pending">Pending</option>
<option value="Shipped" id="shipped">Shipped</option>
</select>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OrderDate, htmlAttributes: new { @style = "font-size:medium", @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.OrderDate, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OrderNumber, htmlAttributes: new { @style = "font-size:medium", @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.OrderNumber, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
</div>
</div>
<form action="/order/update/@Model.OrderId" method="post" enctype="multipart/form-data">
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" class="btn btn-primary" />
</div>
</div>
</form>
</div>
}
}
else
{
<h4>Order Has Been Shipped!</h4>
}
无论使用的语法是否正确,我的提交按钮都不起作用。当我按下按钮时,什么也没有发生,就好像我没有点击它一样,没有任何重定向。
一直工作到昨天。没有更改任何有关表单或相应控制器的代码。
这是表单对应的控制器。
[HttpGet]
[Authorize(Roles = "ADM")]
public ActionResult Update(Guid Id)
{
BusinessLayer.Orders order = new BusinessLayer.Orders();
return View(order.GetOrder(Id));
}
[HttpPost]
[Authorize(Roles = "ADM")]
public ActionResult Update(CommonLayer.ORDER order, Guid id)
{
BusinessLayer.Orders blorder = new BusinessLayer.Orders();
blorder.UpdateOrder(order);
return RedirectToAction("UpdateDetails", new {id=id});
}
【问题讨论】:
-
使用
@Html.BeginForm并将@Model.OrderId移动到<input type="hidden">。 -
我已经在使用 @ 和 if,所以当我尝试将它与 using aswell 一起使用时会显示错误
-
我的意思是,使用它而不是您的手动
<form>标签。我没有注意到您顶部还有一个BeginForm,这使它成为一个嵌套表单,这不是一个有效的html。只需删除<form>然后将路由参数放入BeginForm。 -
仍然没有工作 :( 这一直工作到昨天,我不知道会发生什么,因为我没有更改表单或相应控制器中的任何内容
-
与这个问题本身无关,但对我来说,我的按钮不在
using (Html.BeginForm) {}内,记住它需要在里面。把它移到里面对我有用
标签: c# asp.net-mvc asp.net-mvc-4 model-view-controller