我的查看提交按钮没有响应。它无法调用[Httppost]方法请检查下面的代码。当我点击提交时,视图或控制器没有响应。我的httpGet和Httppost方法名称相同。
* View
@model MT566_PSS.Models.EventController
@{
ViewBag.Title = "Assign Controller";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("EventAssign", "ShowMessage", new { extMsgId = Model.ExternalMessageId, userId = Session["commitId"], currentController = Model.COMMIT_ID }, FormMethod.Post, new { id = "formPosted1" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="BNYMInputBox" id="BlotterSelection">
<div class="InputBoxHeader">
<h3>Assign Controller</h3>
</div>
<div><span id="postResult"></span></div>
<div id="inputFields">
@Html.DropDownListFor(m => m.ID, Model.UserList, "Select", new { @id = "SelectedValue" })
<input type="submit" value="Submit" id="Submit" />
@Html.ActionLink("Back to List", "GetExtMsg")
</div>
</div>
}
* Controller
[HttpPost]
public ActionResult EventAssign(int extMsgId = 0, string userId = "", string currentController = "")
{
T_REVIEW_EVENT_ID revent = _dbContext.T_REVIEW_EVENT_ID.FirstOrDefault(x => x.EXT_MSG_ID == extMsgId);
if (revent != null)
{
revent.CTRL_COMMIT_ID = userId;
}
_dbContext.SaveChanges();
var log = new T_LOG
{
EXT_MSG_ID = extMsgId,
COMMIT_ID = userId,
AFFECTED_DATE = DateTime.Now,
COMMENTS = currentController + " Changed to:" + userId,
CHANGED_COLUMN = "Table: " + "T_Review_Event_Id, " + "Column: " + "CTRL_INDICATOR",
OLD_VALUE = currentController,
NEW_VALUE = "Controller: " + userId,
APPLIED_LEVEL = ""
};
_dbContext.T_LOG.Add(log);
_dbContext.SaveChanges();
ViewData["result"] = "Updated..!!";
return View("Result");
}
答案 0 :(得分:0)
确保为动作和控制器传递正确的值。根据您的代码&#34; EventAssign&#34;是你的行动和#34; ShowMessage&#34;是你的控制者。而不是像这样传递值
@using (Html.BeginForm("EventAssign", "ShowMessage", new { extMsgId = Model.ExternalMessageId, userId = Session["commitId"], currentController = Model.COMMIT_ID }, FormMethod.Post, new { id = "formPosted1" }))
{
...........
............
}
您可以使用隐藏字段传递值
@using (Html.BeginForm("EventAssign", "ShowMessage", FormMethod.Post, new { id = "formPosted1" }))
{
<input type="hidden" name="extMsgId" id="extMsgId" value="@Model.ExternalMessageId"></input>
<input type="hidden" name="userId" id="userId" value="@Session["commitId"]"></input>
<input type="hidden" name="currentController" id="currentController" value="@Model.COMMIT_ID"></input>
...........
............
}
我希望这对你有所帮助。