window.location.href发送多个参数asp.net mvc [英] window.location.href send multiple parameters asp.net mvc

查看:121
本文介绍了window.location.href发送多个参数asp.net mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将多个数据发布到actionresult.

I try to post multiple data to actionresult.

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 ;
    }

动作结果:

public ActionResult MyActionResult(string PostData1, string PostData2)
    {
     return view();
    }

我可以发送 PostData1 值,但是不能发送 PostData2 值到actionresult.那么如何使用window.location.href一起发送PostData1和PostData2值?

I can send PostData1 value however i can not send PostData2 value to actionresult.So how can i send PostData1 and PostData2 values together by using window.location.href ?

推荐答案

您是否要将TextBox1和TextBox2的值传递给控制器​​操作?

Are you trying to pass values of TextBox1 and TextBox2 to the controller action?

使用以下代码检查PostData1和PostData2是否具有值.

Use the following code to check if PostData1 and PostData2 have values.

alert(PostData1);
alert(PostData2);

如果它们没有值,则使用Javascript或JQuery来获取文本框值并将它们存储在Javascript变量var PostData1和PostData2中.

If they do not have values then make use of Javascript or JQuery to fetch your textbox values and store them in Javascript variables, var PostData1 and PostData2.

如果值正确,请继续执行以下操作.

If it has correct values proceed below.

您可以尝试以下方法检查其是否有效

You may try the following to check if it works

window.location.href ="Home/MyActionResult?PostData1=SomeThing1&PostData2=SomeThing2";

如果可以,则代替以下代码

If it does works then instead of the following code

window.location.href ="Home/MyActionResult?Page=data&Post=" + PostData1 + PostData2 ;

尝试

window.location.href ="Home/MyActionResult?PostData1=" + PostData1 + "&PostData2=" + PostData2;

让我知道你是否被卡在某处.

Let me know if you get stuck somewhere.

这篇关于window.location.href发送多个参数asp.net mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆