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

61,675

Solution 1

Try with this:

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

Solution 2

Try this

var url = '@Url.Action("../Home/MyActionResult")' + '?Page='+data+'&'+PostData;
window.location.href = url;
Share:
61,675
Admin
Author by

Admin

Updated on July 27, 2022

Comments

  • Admin
    Admin almost 2 years

    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?