Friday, May 20, 2016

Sitecore MVC Call Controller Action on Radio Button Click

Hi All,

 In my current working project I faces a issue, because I am new in sitecore and for MVC as well so I spend lot's of my time to know , how call controller on radio button click.
After a long search I found a article which is very useful that you can found here.
But for my need I need some more for that I am calling the Sitecore MVC controller on radio button click by below code.

 @using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post))
                        {
                            @Html.Sitecore().FormHandler("FeedbackResult", "Feedback")
                            <label class="radio-inline">
                                <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="yes" onclick="this.form.submit();">
                                @Translate.Text("frontend-components-feedbackbox-was-the-information-helpful-yes")
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="no" onclick="this.form.submit();">
                                @Translate.Text("frontend-components-feedbackbox-was-the-information-helpful-no")
                            </label>
                        }


By using "onclick="this.form.submit();" I just commit my form and "@Html.Sitecore().FormHandler("FeedbackResult", "Feedback")" Call the controller Action. It take two parameter first is Controller name & second is Controller Action Result name.
In controller we are also able to use value of selected radio button by Id as below:

public ActionResult Feedback(String inlineRadioOptions)

        { ....}

Hope that is helpful. Keep doing coding.

Thanks
Arun Sharma


No comments:

Post a Comment