Ha66y-Day
Ha66y-Day

Reputation: 217

Having trouble getting the value of the selected radio button in MVC. Whatever value is listed first is the value i get back to controller.

I am having trouble passing the value of the selected radio button to my controller. Whatever radio button i have listed first is the value i get back to my controller. For example "tst" is always returned

VIEW WITH JQUERY

<div class="atk-radio-center">
            <div>                   
                    @Html.RadioButtonFor(m => m.Impact, "tst", new { Checked = "checked" })
                    Yes
                    @Html.RadioButtonFor(m => m.Impact, "0")
                    No
            </div>
        </div>
<script>
$("#btnContinue").click(function () {
    $.post("/Start/SaveServiceAffectd",
        {
            impact: $('#Impact').val(),
            description: $('#Description').val(),

        },
        function (data) {
            if (data == "true") {

            } else {

            }
        });
});

CONTROLLER

 [HttpPost]
    public bool SaveServiceAffectd(string impact, string description)
    {
        try
        {
            var jobs = new JobRepository();
            jobs.UpdateUserJob(PCSSession.Current.CurrentJob.id, impact, description);
            return true;
        }
        catch(Exception ex)
        {
            return false;
            throw ex;              
        }


    }

VIEW MODEL

    [Required(ErrorMessage = "Work Description is required")]
    [Display(Name = "Description")]
    public string Description { get; set; }

    [Required(ErrorMessage = "Answer for Impact is required")]
    public string Impact { get; set; }

Upvotes: 0

Views: 78

Answers (1)

Ha66y-Day
Ha66y-Day

Reputation: 217

impact: $("input[name='Impact']:checked").val(),

This is what i needed to change my JQUERY to in order to pass correct value

Upvotes: 1

Related Questions