Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window.location.href post parameters to actionresult asp.net mvc

I try to post textbox value to actionresult in asp.net mvc

Javascript:

function OnButtonClick() {
    var data= {
        TextBox: TextBox.GetValue()
    };
    var PostData= data.TextBox;

    window.location.href = "Home/MyActionResult?Page=data" + PostData;
}

ActionResult

public ActionResult MyActionResult(string PostData)
{
    return view();
}

Whenever I post data to Home/MyACtionResult , PostData is always null,

What am I missing ?

How can I post textbox value to actionresult?

like image 530
user3389856 Avatar asked Mar 06 '14 19:03

user3389856


2 Answers

Try with this:

window.location.href = "Home/MyActionResult?Page=data&PostData=" + PostData;
like image 96
thepirat000 Avatar answered Sep 22 '22 05:09

thepirat000


Try this

var url = '@Url.Action("../Home/MyActionResult")' + '?Page='+data+'&'+PostData;
window.location.href = url;
like image 34
Aiswarya Shankar Avatar answered Sep 18 '22 05:09

Aiswarya Shankar