Javascript 如何将文本框值传递给控制器

Javascript 如何将文本框值传递给控制器,javascript,jquery,html,asp.net-mvc-4,Javascript,Jquery,Html,Asp.net Mvc 4,我有一个如下的文本框 @using (Html.BeginForm("checkUserType", "Place", new {type = })) { <div id="login"> <div class="userNameLabel">UserName</div> <div class="userNameField"><input type="text"

我有一个如下的文本框

   @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>
    }
试试这个

window.location.href = '@Url.Action( "checkUserType", "Place" )?type='+type
试试这个

window.location.href = '@Url.Action( "checkUserType", "Place" )?type='+type
试试这个

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<% Html.BeginForm("Search", "Employee");%>
<table>
   <tr>
    <td>
        Name:
    </td>
    <td>
        <input type="text" id="SearchText" name="SearchText" style="width: 325px" />
    </td>
    <td> 
    </td>
    <td>
        <input type="submit" id="Search" value="Search" />
    </td>
</tr>
</table>
<% Html.EndForm();%>
希望它能帮助你

试试这个

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<% Html.BeginForm("Search", "Employee");%>
<table>
   <tr>
    <td>
        Name:
    </td>
    <td>
        <input type="text" id="SearchText" name="SearchText" style="width: 325px" />
    </td>
    <td> 
    </td>
    <td>
        <input type="submit" id="Search" value="Search" />
    </td>
</tr>
</table>
<% Html.EndForm();%>

希望它能帮助您

MVC将您的输入名称映射到您的方法参数

但是,当前输入未指定名称:

<input type="text" id="txtUserName"/>

因此,请加上:

<input type="text" name="type" id="txtUserName"/>


它将映射到参数。并从
BeginForm
中删除匿名对象,因为该值将由输入字段提供,因此无需在
表单中执行操作。

MVC将把输入的名称映射到方法的参数

但是,当前输入未指定名称:

<input type="text" id="txtUserName"/>

因此,请加上:

<input type="text" name="type" id="txtUserName"/>


它将映射到参数。并从
BeginForm
中删除匿名对象,因为该值将由输入字段提供,因此无需在
表单中执行操作。

我只需更新您的代码试试这个

 @using (Html.BeginForm("checkUserType", "Place"))
    {
        <div id="login">
            <div class="userNameLabel">
                UserName</div>
            <div class="userNameField">
                <input type="text" id="txtUserName" name="UserName" /><span><input type="submit" value="ok" id="ok" /></span></div>
        </div>
    }

我只是更新你的代码试试这个

 @using (Html.BeginForm("checkUserType", "Place"))
    {
        <div id="login">
            <div class="userNameLabel">
                UserName</div>
            <div class="userNameField">
                <input type="text" id="txtUserName" name="UserName" /><span><input type="submit" value="ok" id="ok" /></span></div>
        </div>
    }

请显示您的操作方法,如果您要获取请求,那么您的代码至少需要更改如下
window.location.href='@Url.action(“checkUserType”,“Place”)'+'?type='+typewindow.location.href='@Url.Action(“checkUserType”,“Place”)'+'/'+type;获取
type
参数,则使用code>或类似方法@tpeczek-我编辑了我的代码。希望你能看到。然后你应该去
表格
,以获得POST请求(你应该看看@NeerajDubey答案)。@tpeczek按照Neeraj说的做。我遇到了一个问题什么样的问题?请显示您的操作方法,如果您要获取请求,那么您的代码至少需要更改如下
window.location.href='@Url.action(“checkUserType”,“Place”)'+'?type='+typewindow.location.href='@Url.Action(“checkUserType”,“Place”)'+'/'+type;获取
type
参数,则使用code>或类似方法@tpeczek-我编辑了我的代码。希望你能看到。然后你应该去
表格
,以获得POST请求(你应该看看@NeerajDubey答案)。@tpeczek按照Neeraj说的做。我有个问题什么问题?