0
我有一個MVC ActionLink,它轉到名爲Register
的控制器操作。MVC ActionLink轉到獲取操作控制器而不是具有相同名稱的後控制器
我有兩個Register
動作,一個標有HttpGet
和其他與HttpPost
,但是當我嘗試發佈到這個動作它去GET Register
方法而不是POST操作。
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
@Html.ActionLink("Register", "Register", "Home", new { @class = "btn btn-default" }, new { onclick = "RegisterLoader()" })
</div>
</div>
這裏是腳本
function RegisterLoader() {
var url = '@Url.Action("Register", "Home", new { FormMethod.Post })';
$("#divLoading").show();
$.post(url, null,
function (data) {
$("#PID")[0].innerHTML = data;
$("#divLoading").hide();
});
}
我的控制器看起來像這樣。
[HttpGet]
[AllowAnonymous]
public ActionResult Register()
{
var towns = new List<string> { "Alberton", "Bedfordview", "Benoni", "Boksburg", "Brakpan", "Edenvale", "Germiston", "Kempton Park", "Nigel", "Springs" };
//var townOptions = new SelectList(towns);
ViewBag.Town = new SelectList(towns); //townOptions;
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)