简体   繁体   English

Ajax响应未反映在弹出视图中

[英]Ajax respond is not reflected into pop-up view

I have created a button to pass some parameters to a controller and get the response in a responsive pop-up. 我创建了一个按钮,将一些参数传递给控制器​​,并在响应弹出窗口中获取响应。 But somehow when I click the button, nothing happens. 但是当我单击该按钮时,什么也没发生。 No error in Dev.Option (F12), and I already make sure the parameter goes into my controller. Dev.Option(F12)中没有错误,并且我已经确保参数进入我的控制器。

My reference : http://aspsnippets.com/Articles/Open-Show-jQuery-Dialog-Modal-Popup-after-AJAX-Call-Success.aspx 我的参考: http : //aspsnippets.com/Articles/Open-Show-jQuery-Dialog-Modal-Popup-after-AJAX-Call-Success.aspx

I'm using MVC C# on Visual Studio 2010. Below is my code: 我在Visual Studio 2010上使用MVC C#。以下是我的代码:

My home page, all pre-requisite Jquery are already automatically reloaded inside global.asax. 我的主页,所有必备的Jquery已经自动重新加载到global.asax中。

HomePage.cshtml HomePage.cshtml

var externalID = "123";
var susbcrNo = "456";
<a href="#COV" onclick="javascript:CustomerOneView.displayPopUpWindow(@externalID, @susbcrNo);" >DETAILS</a>
<div id="dialog" style="display: none"/>

@section Scripts{
<script type="text/javascript" src="@Url.Content("~/Scripts/CustomerOneView.js")" ></script>
<script type="text/javascript">

    $("#dialog").dialog({
        autoOpen: false,
        modal: true,
        title: "Details",
        buttons: {
            Close: function () {
                $(this).dialog('close');
            }
        }
    });

Inside CustomerOneView.js : CustomerOneView.js内部:

var CustomerOneView = (function () {
return {
    init: function () {
    },
    displayPopUpWindow: function (externalID, susbcrNo) {

        var postData = {
            externalID: externalID,
            susbcrNo: susbcrNo
        };

        $.ajax({
            type: "POST",
            url: "/Home/OneViewDetails",
            data: JSON.stringify(postData),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                $("#dialog").html(r);
                $("#dialog").dialog("open");
            }
        });
    }
};

})();

$(document).ready(function () {
CustomerOneView.init();
});

My controller : 我的控制器

[HttpPost]
public JsonResult OneViewDetails(string externalID, string susbcrNo)
{
    Models deviceDetails = new Models();
    deviceDetails.Code = externalID;
    deviceDetails.Message = susbcrNo;

    // call log here make sure the values.
    Logger.Debug("COV called here " + externalID + " - " + susbcrNo);

    // old return
    // return Json(deviceDetails, JsonRequestBehavior.DenyGet);
    return Json(deviceDetails);
}

My Controller is already tied into a view that supposed to be a pop-up view. 我的控制器已经绑定到一个应该是弹出视图的视图中。 Let's call it PopUp.cshtml 我们称之为PopUp.cshtml

How can I fix this issue? 如何解决此问题?

I need to clarify something about C# on the server side; 我需要在服务器端澄清一些有关C#的内容; if you return a value on a function/method, it will return the value to the code that called said function/method as opposed to intelligently guessing that you want to print the value back to the client so the browser may then manipulate the results? 如果您在函数/方法上return一个值,它将返回该值到调用所述函数/方法的代码中,而不是智能地猜测您想将该值print回客户端,以便浏览器随后可以操纵结果?

If that is the case, you need to echo or print the return value from the function/method or from where the function/method is called. 在这种情况下,您需要从函数/方法或调用函数/方法的地方echoprint返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM