@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});
}
答案 0 :(得分:2)
使用以下代码,如果不起作用,请告知我们
添加以下行以传递orderid
@ Html.HiddenFor(model =&gt; model.OrderId)
更新以下行以调用控制器的操作
Html.BeginForm( “更新”, “命令”,FormMethod.Post)
最后删除了不必要的表单标记
从视图中删除了antiforgerytoken,因为您没有检查您的操作方法。 如果你想添加它,那么你需要在Update Action方法的[httppost]之后添加[ValidateAntiForgeryToken]
<?php
$con=mysqli_connect("localhost","root","","kluby ranking");
// select record from mysql
$sql="SELECT * FROM europa";
$result=mysqli_query($con,$sql);
?>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td colspan="5" bgcolor="#FFFFFF"><strong>Delete data in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Nacja</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>LiczbaPkt</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['ID']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Nacja']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['LiczbaPkt']; ?></td>
<td bgcolor="#FFFFFF"><a href="usuw2.php?ID=<? echo $rows['ID']; ?>">delete</a></td>
</tr>
<?php
// close while loop
}
?>
</table>
<?php
// close connection;
mysqli_close($con);
?>
<?php
$con=mysqli_connect("localhost","root","","kluby ranking");
// get value of id that sent from address bar
$id=$_GET['ID'];
// Delete data in mysql from row that has this id
$sql="DELETE FROM europa WHERE ID='ID'";
$result=mysqli_query($con,$sql);
// if successfully deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='usuw.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysqli_close($con);
?>