下面是我的.cshtml中的代码,有两个按钮,但是我无法通过点击任何按钮来调用我的动作方法。
@model IList<ClaimBuildMVC.ClaimBuildBE.ManageUsersBE>
@{
ViewBag.Title = "GetEditRecord";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="Content-inner-pages">
<div class="Accountsettings">
<h2><span>Edit User Details</span></h2>
<div class="box">
<div class="box-content">
<div class="form-horizontal form-details">
<div class="form-group">
<label class="col-xs-4 col-sm-4 col-md-2 control-label">First Name</label>
<div class="col-xs-8 col-sm-8 col-md-4">
@Html.TextBox("FirstName", (string)ViewBag.FirstName, new { @class = "form-control", @id = "FirstName" })
</div>
</div>
<div class="form-group">
<label class="col-xs-4 col-sm-4 col-md-2 control-label">Last Name</label>
<div class="col-xs-8 col-sm-8 col-md-4">
@Html.TextBox("LastName",(string)ViewBag.LastName, new { @class = "form-control", @id = "LastName" })
</div>
</div>
<div class="form-group">
<label class="col-xs-4 col-sm-4 col-md-2 control-label">Role</label>
<div class="col-xs-8 col-sm-8 col-md-4">
@Html.TextBox("RoleName",(string)ViewBag.FkRoleId,
new { @class = "form-control", @id = "RoleName" })
</div>
</div>
<div class="form-group">
<label class="col-xs-4 col-sm-4 col-md-2 control-label">Status</label>
<div class="col-xs-8 col-sm-8 col-md-4">
@Html.DropDownList("Status", new List<SelectListItem> { new SelectListItem{ Text="Active", Value = "0" }, new SelectListItem{ Text="InActive", Value = "1" }
}, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-xs-8 col-sm-8 col-md-4 col-md-offset-2 col-sm-offset-4 col-xs-offset-4">
<input type="submit" value="Save" name="actiontype" class="btn-class btn-success">
<input type="reset" value="Cancel" name="actiontype" class="btn-class btn-danger">
</div>
</div>
</div>
</div>
</div>
</div>
并在我的控制器
[HttpPost]
public ActionResult GetEditRecord(ManageUsersBE MU,string actiontype)
{
if (actiontype == "Save")
{
my logic
}
return View("ManageUsersBE");
}
所以当我点击保存按钮后,即使把调试器放在我的控制器上,它也没有调用那个控制器。我错了一些东西。请帮忙
答案 0 :(得分:2)
在表单中包含你的元素,然后才能发布。
使用Razor语法
@using (Html.BeginForm("ACtionName", "ControllerName", FormMethod.Post, new { }))
{
<div class="form-horizontal form-details">
.....
</div>
}
使用纯HTML
<form action="/ControllerName/ActionName" method="post">
<div class="form-horizontal form-details">
.....
</div>
</form>
答案 1 :(得分:1)
您应该使用表单标记来使HTTPPost正常工作。
使用剃须刀
@using(html.beginform())
{
//your html
}
在简单的HTML中,您可以将其作为
<form method="post">
//your html
</form>