按钮在部分视图中“提交”

时间:2012-03-16 14:15:48

标签: vb.net asp.net-mvc-3 razor partial-views

我找不到如何提交部分视图中的表单。

我为网站制作了一种搜索引擎。我想从局部视图中将其添加到布局中。我的问题是,当我点击“提交”时,如果我不在搜索视图中,则不会发生任何事情。

以下是局部视图的代码

@Using Html.BeginForm(IsPost)
    @Html.TextBox("SearchString") 
   @<input type="submit" value="Go!"/>
End Using

如果我希望它能正常工作,我该如何参数?

Namespace MvcApplication4
Public Class SearchController
    Inherits System.Web.Mvc.Controller

    Private db As schema_crmEntities = New schema_crmEntities
'
' GET: /Search
Function Index() As ActionResult
    Return View()
    End Function

    '
    ' POST: /Search
    <HttpPost()>
    Function Index(search As String) As ActionResult
        Dim chaine As String = Request("searchString")

    [...]
        Dim model = New SearchModel With {
            .Meetings = meetings,
            .Interviews = interviews,
            .Opportunites = opportunites,
            .Clients = clients,
            .Contacts = contacts
            }

        Return View(model)
    End Function
End Class
End Namespace

  <form method="post" action="/(S(v1sax2fo0frbeuw1ul1xcoet))/Search"><input type="text" value="" name="SearchString" id="SearchString"/>            

   <input type="submit" value="Go!"/>
  </form>

2 个答案:

答案 0 :(得分:4)

确保指定控制器和您要发布到的操作:

@Using Html.BeginForm("MyAction", "MyController", FormMethod.Post)
    @Html.TextBox("SearchString") 
    @<input type="submit" value="Go!"/>
End Using

答案 1 :(得分:2)

您想要像这样更改Html.BeginForm的重载:

@Using Html.BeginForm("action", "controller", FormMethod.Post)

更新:

看起来这个问题与在web.config中启用cookieless会话有关,该会话将(S(v1sax2fo0frbeuw1ul1xcoet))字符串添加到网址。