我尝试将多个数据发布到actionresult. function OnButtonClick() { var data = { TextBox1: TextBox1.GetValue(), TextBox2: TextBox2.GetValue() }; var PostData1 = data.TextBox1; var PostData2 = data.TextBox2;window.location.href ="Home/
function OnButtonClick() { var data = { TextBox1: TextBox1.GetValue(), TextBox2: TextBox2.GetValue() }; var PostData1 = data.TextBox1; var PostData2 = data.TextBox2; window.location.href ="Home/MyActionResult?Page=data&Post=" + PostData1 + PostData2 ; }
的ActionResult:
public ActionResult MyActionResult(string PostData1, string PostData2) { return view(); }
我可以发送PostData1值但是我无法将PostData2值发送到actionresult.那么如何使用window.location.href将PostData1和PostData2值一起发送?
您是否尝试将TextBox1和TextBox2的值传递给控制器操作?使用以下代码检查PostData1和PostData2是否具有值.
alert(PostData1); alert(PostData2);
如果他们没有值,那么使用Javascript或JQuery来获取文本框值并将它们存储在Javascript变量var varData1和PostData2中.
如果它具有正确的值,请继续执
您可以尝试以下方法来检查它是否有效
window.location.href ="Home/MyActionResult?PostData1=SomeThing1&PostData2=SomeThing2";
如果确实有效,则代替以下代码
window.location.href ="Home/MyActionResult?Page=data&Post=" + PostData1 + PostData2 ;
试试这个
window.location.href ="Home/MyActionResult?PostData1=" + PostData1 + "&PostData2=" + PostData2;
如果你被困在某个地方,请告诉我.