在新窗口中打开jquery get请求

在新窗口中打开jquery get请求,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我试图通过ajax调用在dropdownlist中获取数据,调用控制器并在新窗口中获取结果 到目前为止,我已经尝试过: $(document).ready(function () { $('#seeTemplates').click(function () { var template = $('#templates').val(); alert("templateOpen!"); alert(template);

我试图通过ajax调用在dropdownlist中获取数据,调用控制器并在新窗口中获取结果

到目前为止,我已经尝试过:

$(document).ready(function () {

    $('#seeTemplates').click(function () {
        var template = $('#templates').val();

        alert("templateOpen!");

        alert(template);

        window.open($.get("@Url.Action("SeeTemplateDetailsByName", "EbayTemplate")", {
            templateName: template
        }));
    });
}
因此,当用户点击链接时,我希望获得的数据将在新窗口中打开

这里是控制站:

public ActionResult SeeTemplateDetailsByName(string templateName)
{
    EbayTemplateInfo ebayTemplateToShow = mEbayTemplateManager.GetTemplateByName(templateName);

    if (ebayTemplateToShow == null)
    {
        TempData[MessageDomain.Tags.TEMPDATA_MESSAGE_ERROR] = NODATAFOUND;

        return RedirectToAction("EbayTemplateSearchIndex");
    }

    return View(ebayTemplateToShow);
}
它工作正常,但打开的窗口显示:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /Card/[object Object]

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
url是这样的:
http://localhost:63779/Card/[object%20Object]
我不明白为什么会这样。

您正在将一个窗口传递给
窗口。打开
,这不是它所期望的,请查看需要传递哪些参数

您是否尝试过这样做:

window.open("/EbayTemplate/SeeTemplateDetailsByName?templateName=" + template);
  • 这是电话,不是邮件。使用$.get时,Razor会将“[System.Web.Http.HttpGet]”作为控制器上的属性之一。这可以确保您正在进行正确的调用,并且应用程序知道这是一个“Get”

  • 确保JSON对象与控制器上的传入值匹配。您可以为要传递回控制器的对象创建一个模型,并声明:“modelOjbect templateName”,也可以确保在调用window.open(“URL?templateName=“+JSON.stringify(templateName))时,使用参数中的JSON.stringify(templateName))将对象作为字符串传递回


  • 希望有帮助

    $。访问该url可能会返回一个JavaScript对象,其中包含属性。您需要稍微扩展代码,以便从返回的对象中指定所需的字符串。啊,不,我没有。我会试试的。非常感谢,它成功了!谢谢你提供的额外信息。没问题,很高兴它帮助了你