C# 提交按钮不工作!MVC
使用下面的代码,让我们知道如果不工作 在下面的行中添加以传递orderid @Html.HiddenFor(model=>model.OrderId) 更新了以下行以调用控制器的操作 BeginForm(“更新”,“订单”,FormMethod.Post) 最后删除了不必要的表单标记 已从视图中删除antiforgerytoken,因为您没有签入操作方法。 如果您想添加它,那么需要在更新操作方法的[httppost]之后添加[ValidateAntiForgeryToken]C# 提交按钮不工作!MVC,c#,asp.net-mvc,asp.net-mvc-4,model-view-controller,C#,Asp.net Mvc,Asp.net Mvc 4,Model View Controller,使用下面的代码,让我们知道如果不工作 在下面的行中添加以传递orderid @Html.HiddenFor(model=>model.OrderId) 更新了以下行以调用控制器的操作 BeginForm(“更新”,“订单”,FormMethod.Post) 最后删除了不必要的表单标记 已从视图中删除antiforgerytoken,因为您没有签入操作方法。 如果您想添加它,那么需要在更新操作方法的[httppost]之后添加[ValidateAntiForgeryToken] [HttpGet]
[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});
}
@model CommonLayer.ORDER
@{
ViewBag.Title=“更新”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
更新订单状态
@如果(Model.OrderStatus!=“已发货”)
{
使用(Html.BeginForm(“Update”、“Order”、FormMethod.Post))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model=>model.UserId)
@Html.HiddenFor(model=>model.OrderId)
@LabelFor(model=>model.OrderId,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
@EditorFor(model=>model.OrderId,new{htmlAttributes=new{@class=“form control”,@readonly=“readonly”})
@LabelFor(model=>model.OrderStatus,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
悬而未决的
装船
@LabelFor(model=>model.OrderDate,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
@EditorFor(model=>model.OrderDate,new{htmlAttributes=new{@class=“form control”,@readonly=“readonly”})
@LabelFor(model=>model.OrderNumber,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
@EditorFor(model=>model.OrderNumber,new{htmlAttributes=new{@class=“form control”,@readonly=“readonly”})
}
}
其他的
{
订单已发货!
}
使用下面的代码,如果不起作用,请告诉我们
在下面的行中添加以传递orderid
@Html.HiddenFor(model=>model.OrderId)
更新了以下行以调用控制器的操作
BeginForm(“更新”,“订单”,FormMethod.Post)
最后删除了不必要的表单标记
已从视图中删除antiforgerytoken,因为您没有签入操作方法。
如果您想添加它,那么需要在更新操作方法的[httppost]之后添加[ValidateAntiForgeryToken]
[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});
}
@model CommonLayer.ORDER
@{
ViewBag.Title=“更新”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
更新订单状态
@如果(Model.OrderStatus!=“已发货”)
{
使用(Html.BeginForm(“Update”、“Order”、FormMethod.Post))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model=>model.UserId)
@Html.HiddenFor(model=>model.OrderId)
@LabelFor(model=>model.OrderId,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
@EditorFor(model=>model.OrderId,new{htmlAttributes=new{@class=“form control”,@readonly=“readonly”})
@LabelFor(model=>model.OrderStatus,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
悬而未决的
装船
@LabelFor(model=>model.OrderDate,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
@EditorFor(model=>model.OrderDate,new{htmlAttributes=new{@class=“form control”,@readonly=“readonly”})
@LabelFor(model=>model.OrderNumber,htmlAttributes:new{@style=“font size:medium”,@class=“control label col-md-2”})
@EditorFor(model=>model.OrderNumber,new{htmlAttributes=new{@class=“form control”,@readonly=“readonly”})
}
}
其他的
{
订单已发货!
}
使用并将@Model.OrderId
移动到
中。我已经将@与if一起使用,因此当我尝试将其与using一起使用时会显示错误。我的意思是,使用它而不是手动的
标记。我没有注意到您的顶部还有一个BeginForm
,这使它成为一个嵌套表单,它不是有效的html。只需删除
,然后将路线参数放入通知中即可。仍然不起作用:(这直到昨天才开始工作,我不知道会发生什么,因为我没有更改表单中的任何内容或相应的控制器本身与此问题无关,但对我来说,我的按钮不在使用(Html.BeginForm){}的中
记住它需要在里面。将它移到里面对我有用,并将@Model.OrderId
移到
中。我已经将@与if一起使用了,所以当我尝试将它与using一起使用时会显示错误。我的意思是,使用它而不是手动的
标记。我没有
@model CommonLayer.ORDER
@{
ViewBag.Title = "Update";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h4>Update Order Status</h4>
<br />
@if (Model.OrderStatus != "Shipped")
{
using (Html.BeginForm("Update","Order",FormMethod.Post))
{
<div class="form-horizontal">
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.UserId)
@Html.HiddenFor(model => model.OrderId)
<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>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" class="btn btn-primary" />
</div>
</div>
</div>
}
}
else
{
<h4>Order Has Been Shipped!</h4>
}