Asp.net mvc 4 MVC 4表单-提交按钮没有';我什么也不做

Asp.net mvc 4 MVC 4表单-提交按钮没有';我什么也不做,asp.net-mvc-4,post,submit,Asp.net Mvc 4,Post,Submit,试图在MVC4(+Razor)中实现表单,但submit按钮没有做任何事情 控制器(应获得post操作): public class GeneralController { [HttpPost] public ActionResult SearchResults(SearchParamsModel searchParams) { // doin some stuff here return View("SearchResultsView")

试图在MVC4(+Razor)中实现表单,但submit按钮没有做任何事情

控制器(应获得post操作):

public class GeneralController
{
    [HttpPost]
    public ActionResult SearchResults(SearchParamsModel searchParams)
    {
        // doin some stuff here
        return View("SearchResultsView");
    }
}
@model Models.SearchParamsModel 

@using (Html.BeginForm("SearchResults", "General", FormMethod.Post))
 {
  <section class="form-field">
    <input type="text" name="Property1" id="Property1" class="field
                  field139 autocomplete-init-no-img" />
    <label for="Property1">value1</label>
    <input type="submit" value="some value" 
                    class="submit btn blue-btn special-submit" />   
  </section>
 }
查看(.cshtml)


Html.BeginForm助手将为您创建表单标记,请尝试

查看:

public class GeneralController
{
    [HttpPost]
    public ActionResult SearchResults(SearchParamsModel searchParams)
    {
        // doin some stuff here
        return View("SearchResultsView");
    }
}
@model Models.SearchParamsModel 

@using (Html.BeginForm("SearchResults", "General", FormMethod.Post))
 {
  <section class="form-field">
    <input type="text" name="Property1" id="Property1" class="field
                  field139 autocomplete-init-no-img" />
    <label for="Property1">value1</label>
    <input type="submit" value="some value" 
                    class="submit btn blue-btn special-submit" />   
  </section>
 }
@model Models.SearchParamsModel
@使用(Html.BeginForm(“SearchResults”、“General”、FormMethod.Post))
{
价值1
}

如果您只需要实现搜索,而不需要使用ViewModel,则可以发送带有搜索请求的字符串。而且不应该是Post方法:

public ActionResult SearchResults(string searchString)
{
    //code for searching

    return View(yourmodel);
}
在视图中

@using (Html.BeginForm())
{     
    Searching: @Html.TextBox("SearchString")
    <input type="submit" value="Search"/>
}
@使用(Html.BeginForm())
{     
搜索:@Html.TextBox(“搜索字符串”)
}

如果我在MVC4或MVC5中也这样做,我会得到相同的结果

查看在所有控件周围添加
标记:

@using (Html.BeginForm("SearchResults", "General", FormMethod.Post))
{
  <fieldset>
  // your controls...
  <input type="text" name="Property1" id="Property1" class="field field139 autocomplete-init-no-img" />
  <label for="Property1">value1</label>
  <input type="submit" value="some value" class="submit btn blue-btn special-submit" />      
  // if you need a partial form included:
  @{Html.RenderPartial("_SomeOtherPartial", @Model);}
  // etc..
  </fieldset>
}
@使用(Html.BeginForm(“SearchResults”、“General”、FormMethod.Post))
{
//你的控制。。。
价值1
//如果您需要包含部分表格:
@{Html.RenderPartial(“_SomeOtherPartial”,@Model);}
//等等。。
}
试试看


让我知道

您嵌套了两个表单,因此“提交”按钮仅适用于内部表单。您从不提交外部表单。外部表单是使用Html.BeginForm帮助程序创建的,从未被激发。谢谢。Html.BeginForm应该正好位于?不管怎么说,它不起作用……可能还缺少什么东西控制器被激活了吗?如果是这样,请编辑您的控制器以使用FormCollection按名称提取表单值,如下图所示。不,控制器未被激发。首先,我要调试调用(之后,我将致力于显示结果…),谢谢,我将尝试。但是我确实希望我的代码是干净的,我的搜索有多个输入参数,我不想用纯字符串来维护搜索..谢谢,我按照你的建议做了。但是它不起作用。只有当我在.cshtml@{Layout=null}的开头添加它时,它才起作用(为了简化事情,让我们只说我有一个没有字段的按钮,我想到达控制器),这对我很有帮助!谢谢