我在一个视图中有3个单选按钮和2个文本框。最初,我需要通过视图将值保存在DB中,一旦保存,我需要根据我单击的单选按钮在特定视图中显示保存的值。
一种方法是将值发布到控制器方法中,保存它,然后用值渲染回一个新视图。
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);