我的控制器代码:
public ActionResult groupeditSubmit(List<string> barC, int PID = -1, int TID = -1, string DateT = "", int nPID = -1, int nTID = -1, string nDateT = "")
{
ViewBag.PID = new SelectList(db.Places, "ID", "Name", 0);
ViewBag.TID = new SelectList(db.Transferees, "ID", "FullName", 0);
ViewBag.DateT = DateT;
var studentList = db.Database.ExecuteSqlCommand("Update Barcode set PID = '"+nPID+ "' ,TID='"+nTID+ "' , DateT = '"+nDateT+ "' where (PID = "+PID+ " AND TID = "+TID+ " AND DateT = '"+ DateT + "' )");
db.SaveChanges();
return RedirectToAction("groupedit");
}
我的查看代码:
@model IEnumerable<barkod.Models.Barcode>
@{
ViewBag.Title = "groupedit";
Layout = "~/Views/Shared/_LayoutPanel.cshtml";
}
</form>
@if (Model.Count() > 0)
{
<div class="row text-center">
<form method="post" action="groupeditSubmit">
<table class="table table-responsive">
<tr>
<th>
بارکد
</th>
<th>
مکان
</th>
<th>
تحویل گیرنده
</th>
<th>
تاریخ تحویل
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<input name="barc" value="@Html.DisplayFor(modelItem => item.barC)" class="hidden" />
@Html.DisplayFor(modelItem => item.barC)
</td>
<td>
@Html.DisplayFor(modelItem => item.Place.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Transferee.FullName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateT)
</td>
</tr>
}
</table>
<div class="form-group">
<div class="col-md-10">
@Html.DropDownList("nTID", null, htmlAttributes: new { @class = "form-control", required = "required" })
</div>
</div>
<div class="form-group">
<div class="col-md-10">
@Html.DropDownList("nPID", null, htmlAttributes: new { @class = "form-control", required = "required" })
</div>
</div>
<div class="form-group">
<div class="col-md-10">
@Html.Editor("nDateT", new
{
htmlAttributes = new
{
@class = "form-control"@*, Type = "date"*@,
required = "required",
@Value = ViewBag.DateT
}
})
@*<input type="button" id= "exampleI" class="btn-danger" value="#" name="Date" data-mddatetimepicker="true" data-placement="right" data-trigger="click" data-targetselector="#exampleI" required />*@
</div>
</div>
<div class="form-group hidden">
<div class="col-md-10">
@Html.DropDownList("TID", null, htmlAttributes: new { @class = "form-control", required = "required" })
</div>
</div>
<div class="form-group hidden">
<div class="col-md-10">
@Html.DropDownList("PID", null, htmlAttributes: new { @class = "form-control", required = "required" })
</div>
</div>
<div class="form-group hidden">
<div class="col-md-10">
@Html.Editor("DateT", new
{
htmlAttributes = new
{
@class = "form-control"@*, Type = "date"*@,
required = "required",
@Value = ViewBag.DateT
}
})
@*<input type="button" id= "exampleI" class="btn-danger" value="#" name="Date" data-mddatetimepicker="true" data-placement="right" data-trigger="click" data-targetselector="#exampleI" required />*@
</div>
</div>
<input type="submit" class="btn btn-success" value="ویرایش گروهی" />
</form>
</div>
}
在我的本地主机中可以,但是当它在服务器中运行时,会出现此错误:
“ /”应用程序中的服务器错误。 不允许新事务,因为会话中有其他线程正在运行。 说明:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。 异常详细信息:System.Data.SqlClient.SqlException:不允许新事务,因为会话中正在运行其他线程。