I have a textbox like below
@using (Html.BeginForm("checkUserType", "Place", new {type = }))
{
<div id="login">
<div class="userNameLabel">UserName</div>
<div class="userNameField"><input type="text" id="txtUserName"/><span><input type="button" value="ok" id="ok" /></span></div>
</div>
}
I want to pass the textbox value to my controller. For that I used the below code, but it's not working... Pls help...
Action method
[HttpPost]
public ActionResult checkUserType(string type)
{
var elements = from element in db.USERS
where element.UserType == type
select element;
if (elements == null)
{
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Place/Index");
}
}
window.location.href = '@Url.Action( "checkUserType", "Place" )' + '?type=' + type;or like this if thetypeparameter is being taken from the routewindow.location.href = '@Url.Action( "checkUserType", "Place" )' + '/' + type;Formin order to have POST request (you should look at @NeerajDubey answer).