asp.net-mvc window.location.href 发送多个参数 asp.net mvc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22252184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:34:32  来源:igfitidea点击:

window.location.href send multiple parameters asp.net mvc

asp.net-mvcpostlocationhref

提问by user3392929

I try to post multiple data to actionresult.

我尝试将多个数据发布到 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 ;
    }

ActionResult:

行动结果:

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

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

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

回答by TechnoBrat

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

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

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

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

alert(PostData1);
alert(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.

如果它们没有值,则使用 Javascript 或 JQuery 来获取您的文本框值并将它们存储在 Javascript 变量 var PostData1 和 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 ;

try this

尝试这个

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

Let me know if you get stuck somewhere.

如果你被困在某个地方,请告诉我。

回答by sumityadavbadli

This will work but make sure value1 and value2 should be not null.

这会起作用,但要确保 value1 和 value2 不为空。

window.location.href = "add-categories.php?PostData1=" + value1 + "&PostData2=" + value2;

window.location.href = "add-categories.php?PostData1=" + value1 + "&PostData2=" + value2;

回答by sid busa

This will work 100%

这将工作 100%

 window.location.href = "url?Data1=" + value1 + "&Data2=" + value2;