I am using extremely similar code on another view and controller that is working perfectly but for some reason I cannot get this one to work. No matter what I do the controller parameters show undefined even though name and pass in the javascript are working correctly. Any help would be appreciated!
View:
@using (Html.BeginForm())
{
<fieldset>
<legend>User</legend>
Username:
@Html.TextBox("txtUsername")
<br/>
Password:
@Html.TextBox("txtPassword")
<br />
<p>
<input type="submit" id="btnLogin" value="Login" />
</p>
</fieldset>
}
<script>
$(function() {
$("#btnLogin").click(login);
});
function login() {
var name = $('#txtUsername').val();
var pass = $('#txtPassword').val();
$.post("/User/Login/" + name + "/" + pass, null, loginSuccess, "json");
}
function loginSuccess(result) {
alert(result);
}
</script>
Controller:
public ActionResult Login()
{
return View("Login");
}
[HttpPost]
public JsonResult Login(string name, string pass)
{
string result = "test result";
return Json(result);
}