AbhiJA
AbhiJA

Reputation: 341

How can pass actionlink parameter to controller MVC 5?

How can I pass NextPrevious value to controller?

Now NextPrevious is getting always null

[HttpPost]
    public ActionResult PremiumUserRegistration(PartnersVM partnersVM, string NextPrevious)
    {
        if (NextPrevious != null)
        {
        }
    }

View And .js file,

$('.btnActionNext').click(function () {  
    $(this).closest('form')[0].submit();  
});  
@Html.ActionLink("Next >>", "PremiumUserRegistration", new { controller = "UserRegister" }, new { NextPrevious = "value", @class = "btnActionNext" , onclick = "return false;" })

Please help me...

Upvotes: 0

Views: 480

Answers (2)

KuriosCurious
KuriosCurious

Reputation: 125

If you are submitting a form, then add it as a hidden field

@Html.Hidden("NextPrevious", value)

Otherwise, you entered the "NextPrevious" value in the wrong spot in the ActionLink method. It should be within routeValues, not htmlAttributes. The correct way would be:

@Html.ActionLink("Next >>", "PremiumUserRegistration", new { controller = "UserRegister", NextPrevious = "value" }, new { @class = "btnActionNext", onclick = "return false;" })

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

Add a hidden:

<input type="hidden" name="Action" />

Make sure it's on your form. Next, on your click handler, do:

$('.btnActionNext').click(function () {  
    $("#Action").val("NEXT");
    $(this).closest('form')[0].submit();  
});

In your post action, add string Action:

    [HttpPost]
    public ActionResult PremiumUserRegistration(string Action, PartnersVM partnersVM)
    {
        if (Action == "NEXT")
        {
        }
    }

Upvotes: 1

Related Questions