【问题标题】:Opening a new browser window via JQuery not sending all values via parameters通过 JQuery 打开一个新的浏览器窗口而不是通过参数发送所有值
【发布时间】:2017-08-31 17:53:41
【问题描述】:

windows.open() 有问题;

  • 框架:Asp.netMVC
  • 代码:C#,Razor
  • 问题:jquery

当函数触发时,它应该向控制器发送参数 firstnamelastnamedobgender 但我遇到了一个问题,它只发送 firstname 并且其他参数为空。当我在客户端调试它时,它显示所有参数都有值但是当它调用操作结果时它只发送一个参数。

$(document).ready(function() {

     $(".ViewGet").click(function () {
         var firstname = $(this).closest("tr").find(".firstname").text();
         var lastname = $(this).closest("tr").find(".lastname").text();
         var dob = $(this).closest("tr").find(".dob").text();
         var gender = $(this).closest("tr").find(".gender").text();

         window.open('@Url.Action("FindClientsFor","ClientSerach")?lastname=' + firstname, "&" + +"firstname=" + lastname + "&dob=" + dob + "&gender=" + 1 + 'popUpWindow', 'height=750, width=960, left=300, top=100, resizable=yes, scrollbars=yes, toolbar=yes, menubar=no, location=no, directories=no, status=yes');

     });
});

控制器

[HttpGet]
public ActionResult FindClients(string firstname, string lastname, string dob, int? gender,FormCollection collection)
{
     if (IsNullOrEmpty(firstname) || IsNullOrEmpty(lastname) || IsNullOrEmpty(dob) || gender == null)
     {
         return RedirectToAction("Index");
     }
     else
     {
         var obj = _repo.ClientSearchWithAll(firstname, lastname, dob, gender);
         //_repo.SortUserNames(obj);
         return View(obj);
     }
}

【问题讨论】:

    标签: javascript c# jquery asp.net window.open


    【解决方案1】:

    您的window.open 参数存在严重的串联问题。

    您使用了 + +firstname, "&" 破坏了连接,并忘记在 window.open 第二和第三个参数之前传递逗号 (,)。

    您还混合了 firstnamelastname 变量。

    试试这个:

    window.open('@Url.Action("FindClientsFor","ClientSerach")?lastname=' + lastname + '&firstname=' + firstname+ '&dob=' + dob + '&gender=1', 'popUpWindow', 'height=750, width=960, left=300, top=100, resizable=yes, scrollbars=yes, toolbar=yes, menubar=no, location=no, directories=no, status=yes');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      相关资源
      最近更新 更多