asp.net-mvc-3-areas

call action methods in @Html.RadioButtonFor in MVC3


I have 3 radio buttons and 2 text boxes in a view. Initially I need to save the values in DB through the view and once its saved I need to display the saved values in the particular view according to which radio button I clicked.


Solution

  • This got solved. We can use JQuery to achive tgis
    
    View
    --------
    
      var url = '@Url.Action("YourActionName", "YourControllerName")';
      $.post(url, 'ID=' + radio button Id , function (data) {   
             $('#txtBox1').val(data.Key1);         
             $('#txtBox2').val(data.Key2);  
             $('#txtBox3').val(data.Key3);  
    }
    
    Controller
    ----------
     Inside your action method , construct a JSON string as showed below and send back to JQuery Function.
    
      var dataTest = new { "Key1"= "value1","Key2"= "value2", "Key3"= "value3" };  
      return Json(dataTest, JsonRequestBehavior.AllowGet);