gpt4 book ai didi

c# - 没有模型的 MVC 5 Html.BeginForm

转载 作者:可可西里 更新时间:2023-11-01 08:42:27 24 4
gpt4 key购买 nike

我的 _Layout 页面上有一个简单的搜索表单。

如何轻松地将值从 search-fld 传递到 Controller ?无需创建模型或 View 模型。

@using (Html.BeginForm("Search", "Home", new { id = "search-fld" }, FormMethod.Post, new { @class = "header-search pull-right" }))
{
@Html.AntiForgeryToken()

<input type="text" placeholder="Search" id="search-fld">
<button type="submit">
<i class="fa fa-search"></i>
</button>
}

如果我运行这个然后“search-fld”被发送到 Controller (offcourse)

改用 Ajax 表单并使用 Jquery 获取值?

最佳答案

只需给您的 input 一个 name 属性:

<input type="text" placeholder="Search" id="search-fld" name="searchValue">

然后将该名称与 Controller HttpPost 方法中的参数匹配:

[HttpPost]
public ActionResult Search(string searchValue)

关于c# - 没有模型的 MVC 5 Html.BeginForm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25745459/

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