gpt4 book ai didi

javascript - 如何将文本框值传递给 Controller

转载 作者:行者123 更新时间:2023-11-28 13:41:39 25 4
gpt4 key购买 nike

我有一个如下所示的文本框

   @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>
}

我想将文本框值传递给我的 Controller 。为此,我使用了下面的代码,但它不起作用......请帮忙...

操作方法

[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

关于javascript - 如何将文本框值传递给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17485434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com