Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

ActionResult:

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

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 ?

like image 627
user3392929 Avatar asked Mar 20 '26 22:03

user3392929


1 Answers

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

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

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.

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.

like image 125
TechnoBrat Avatar answered Mar 23 '26 22:03

TechnoBrat