Asp.net mvc 3 参数未从视图正确传递到控制器操作

Asp.net mvc 3 参数未从视图正确传递到控制器操作,asp.net-mvc-3,parameters,null,Asp.net Mvc 3,Parameters,Null,对于我正在使用的应用程序,我有以下Razor代码用于我正在使用的视图: @Html.InputFor(m => m.Property1); // A date @Html.InputFor(m => m.Property2); // Some other date @Html.InputFor(m => m.SomeOtherProperty); // Something else. <a href='#' id='some-button'>Button

对于我正在使用的应用程序,我有以下Razor代码用于我正在使用的视图:

@Html.InputFor(m => m.Property1);   // A date
@Html.InputFor(m => m.Property2);   // Some other date
@Html.InputFor(m => m.SomeOtherProperty);  // Something else.
<a href='#' id='some-button'>Button Text Here</a>

<!-- SNIP: Extra code that dosen't matter -->

<script>
  var $someButton = $('#some-button');

  $(document).ready(function () {
    $someButton.click(function (e) {
      e.preventDefault();
      window.open('@Url.Action("Foo", "Home", new {p1 = Model.Property1, p2 = Model.Property2, pX = Model.SomeOtherProperty})', '_blank');
    });
  });
</script>
我注意到只有第一个参数(
p1
)从前端获取一个值;我的所有其他参数都被传递为空值


问题:当为这些其他字段分配了一些值时,为什么要向ActionResult传递空值?或者,一个补充问题:为什么只有第一个参数成功地传递了它的值,而其他所有参数都失败了?

这个问题是由
URL.Action()
生成的转义URL引起的。(来源:)

只需在
Url.Action()
周围添加一个
@Html.Raw()
调用,数据就会按预期流动

 window.open('@Html.Raw(Url.Action("Foo", "Home", new {p1 = Model.Property1, p2 = Model.Property2, pX = Model.SomeOtherProperty}))', '_blank');

呈现的HTML是什么样子的?当页面加载时,Property2和SomeOtherProperty是否设置为空值?属性1、2和SomeOtherProperty都已填充。值得注意的是,我正在处理的过程需要输入信息,并单击搜索链接。这将提交一份模型副本(包含填写的信息),作为搜索的标准。该信息被填充到子模型列表中,并且该列表的计数大于0,甚至允许显示我正在编码的链接。Andrew,window.open(“@Url.Action(“Foo”,“Home”,new{p1=Model.Property1,p2=Model.Property2,pX=Model.SomeOtherProperty})”,“u blank”);这一行在HTML中生成了什么?当js运行时,不会使用粘贴的输入值。发布生成的URL。我注意到
&以及各种转义字符。@Andrew谢谢:)但我没有自己解决它,只找到了准备好的响应。说实话,我不明白为什么MVC会有这种行为,我总是直接使用参数化的url.action而不使用“raw”。祝你好运:)PS你可以为你的问题添加答案。
public ActionResult Foo(string p1, string p2, string pX)
{
  var workModel = new FooWorkModel
  {
    Property1 = p1,
    Property2 = p2,
    SomeOtherProperty = pX
  };

  // Do something with this model, dosen't really matter from here, though.
  return new FileContentResult(results, "application/some-mime-type");
}
 window.open('@Html.Raw(Url.Action("Foo", "Home", new {p1 = Model.Property1, p2 = Model.Property2, pX = Model.SomeOtherProperty}))', '_blank');