user1005310
user1005310

Reputation: 877

Pass parameter value to action using RedirectToaction MVC3

This is my action method in controller

public ActionResult RedirectToDemoView(string message)
{
    var model = new Error();
    model.Message = message;
    return this.View("Error", model);
}

How do I pass the parameter to this action from my view ( .cshtml) page using jquery ? Here is my code

redirectToAction('@Url.Action("RedirectToDemoView", "Audit" )',
    new { message:$(request.responseText).find('h2').eq(0).text() }); 

It is passing null value to RedirectToDemoView method.

Please help

Upvotes: 0

Views: 1314

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

The following should work:

var message = $(request.responseText).find('h2').eq(0).text();
var url = '@Url.Action("RedirectToDemoView", "Audit")?message=' + encodeURIComponent(message);
redirectToAction(url);

Upvotes: 1

Kundan Singh Chouhan
Kundan Singh Chouhan

Reputation: 14282

Try this instead :

redirectToAction('@Url.Content("~/Audit/RedirectToDemoView?message=")' 
                   + $(request.responseText).find('h2').eq(0).text());

Hope this will help !!

Upvotes: 0

Related Questions