【问题标题】:Ajax Form Begin is not going to http GET methodAjax Form Begin 不会使用 http GET 方法
【发布时间】:2014-10-31 13:41:03
【问题描述】:

我正在尝试以 ajax 形式发送文本框值开始并显示相应的部分视图但问题是它总是使用 post 方法,但我也以 ajax 形式提及 httpmethod

我的代码是

    @using (Ajax.BeginForm("UserMenuPermission", new AjaxOptions { HttpMethod = "Get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "GridData" }))
    {
         <div>
                    @Html.Label("User Name")
                    <input type="text"  placeholder="User Name" style="color: black;height:30px;" name="Username"/>                            
                    <input type="submit" value="Search" />
         </div>
    }

此代码可以将信息传递给 UserMenuPermissionController POST 方法,但我需要传递 GET 方法请朋友帮助我

提前致谢。

【问题讨论】:

  • 无论何时提交,始终是一个帖子。
  • 那是我在局部视图中,这个表单提交按钮它必须进入 http get 方法控制器
  • 但我希望它能够获得方法,我能做什么
  • 嗨 Dinesh,提交按钮总是会发布页面。什么场景,你不想发帖?
  • 如果您在发布表单时遇到任何问题,我建议您删除 Ajax.Begin 表单并使用 JQuery Ajax 处理按钮单击事件。

标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 model-view-controller


【解决方案1】:

我建议使用 jquery.ajax get 方法

//Change your search button like this
<input type="button" value="Search" onclick="ajaxCall()" />
//in javascript
function ajaxCall()
{
 $.ajax({
  url: "ActionURL",
  type:"get", //send it through get method
  data:{} 
  success: function(response) {
    //response is your partialview html
  },
  error: function(xhr) {
    //Do Something to handle error
  }
});

}

在控制器中

public ActionResult GetHtml( )
{
    return PartialView( "UserDetails");
}

【讨论】:

  • 是的,我的 get 方法是返回部分视图,我将如何做到这一点,你能告诉我任何例子吗
猜你喜欢
  • 2012-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多