Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Ajax Jquery在MVC中使用ActionLink后不返回URL_C#_Asp.net Mvc 4 - Fatal编程技术网

C# Ajax Jquery在MVC中使用ActionLink后不返回URL

C# Ajax Jquery在MVC中使用ActionLink后不返回URL,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,我有一个场景: 这是单击ActionLink时我的ActionResult public PartialViewResult ViewHit(string id, string recordid,string statusSelect,string statusHitSelect) { //some code here.... } 单击按钮后要发布的操作链接: public ActionResult SaveUpdate(String statusSelect, string sta

我有一个场景:

这是单击ActionLink时我的ActionResult

 public PartialViewResult ViewHit(string id, string recordid,string statusSelect,string statusHitSelect)
{
    //some code here....
}
单击按钮后要发布的操作链接:

public ActionResult SaveUpdate(String statusSelect, string statusHitSelect)
 {

     return PartialView("ViewHitList");
 }
这是按钮:

<input type="button" value="Save" id="savehit"/>
问题是,当我使用调试模式点击save按钮时,调用的ActionResult是
ViewHit
,而不是
SaveUpdate

我想知道为什么会这样


非常感谢任何好主意。

保存更新不是post类型请在控制器方法顶部添加属性[HttpPost],如

[HttpPost]
public ActionResult SaveUpdate(String statusSelect, string statusHitSelect)
 {

     return PartialView("ViewHitList");
 }
我已经更改了ajax调用,比如bellow,它使用了SaveUpdate方法。下面是ajax调用

  $(document).ready(function () {
        $("#savehit").on('click', function () {
            var statusSelectData="statusSelect";
            var statusHitSelectData="statusHitSelect";
            var postData = {
                statusSelect: statusSelectData,
                statusHitSelect: statusHitSelectData
            }
            //alert("Button was click!");
            $.ajax({
                type: "POST",
                url: "/Home/SaveUpdate",
                data: postData,
                //data:null,
                success: function (response) {
                    if (response != null && response.success) {
                        //InformationMessageSuccess(response.responseText);
                        alert("success");
                    } else {
                        // DoSomethingElse()
                        //InformationMessageFailed(response.responseText);
                        alert("not success");
                    }
                },

            });

        });
    });

SaveUpdate不是post类型请在控制器方法顶部添加属性[HttpPost],如

[HttpPost]
public ActionResult SaveUpdate(String statusSelect, string statusHitSelect)
 {

     return PartialView("ViewHitList");
 }
我已经更改了ajax调用,比如bellow,它使用了SaveUpdate方法。下面是ajax调用

  $(document).ready(function () {
        $("#savehit").on('click', function () {
            var statusSelectData="statusSelect";
            var statusHitSelectData="statusHitSelect";
            var postData = {
                statusSelect: statusSelectData,
                statusHitSelect: statusHitSelectData
            }
            //alert("Button was click!");
            $.ajax({
                type: "POST",
                url: "/Home/SaveUpdate",
                data: postData,
                //data:null,
                success: function (response) {
                    if (response != null && response.success) {
                        //InformationMessageSuccess(response.responseText);
                        alert("success");
                    } else {
                        // DoSomethingElse()
                        //InformationMessageFailed(response.responseText);
                        alert("not success");
                    }
                },

            });

        });
    });

您可以使用
event.preventDefault()


您可以使用
event.preventDefault()

  • 将[HttpPost]属性添加到SaveUpdate操作
  • 在ajax中,将URL更改为URL:“ControllerName/SaveUpdate”
  • 由于您希望将布尔结果(JSON)作为ajax响应返回到页面,因此只需返回jsonResult(true/false)
  • 将[HttpPost]属性添加到SaveUpdate操作
  • 在ajax中,将URL更改为URL:“ControllerName/SaveUpdate”
  • 由于您希望将布尔结果(JSON)作为ajax响应返回到页面,因此只需返回jsonResult(true/false)

  • savehit
    按钮是否在表单中?我的保存按钮上没有表单元素@杰里克茨感谢下面的答案。。但不幸的是,这并没有解决问题。不知道为什么。。。你可以试着用
    ActionLink
    从一开始就模拟问题解决者的做法。
    savehit
    按钮是否在表单中?我的保存按钮上没有表单元素@杰里克茨感谢下面的答案。。但不幸的是,这并没有解决问题。不知道为什么。。。你可以尝试用
    ActionLink
    从一开始就模拟问题人的做法。同样,我也尝试了这个
    url:“Home/SaveUpdate”
    ,但没有运气。在我的调查中,url添加了像
    http://localhost:6487/Home/ViewHit/Home/SaveUpdate
    。这是wierd,不知道为什么。你可以尝试使用UrlHelper。试试我最新的答案。只需确保“保存更新”在
    Home
    controllerAlso iv'e尝试了这个
    url:“Home/SaveUpdate”
    ,但是运气不好。在我的调查中,url添加了像
    http://localhost:6487/Home/ViewHit/Home/SaveUpdate
    。这是wierd,不知道为什么。你可以尝试使用UrlHelper。试试我最新的答案。只需确保“保存更新”在
    主页中
    controllerThanks for your idea@UnniThanks for your idea@Unni