asp.net mvc - Set radio button checked item from ASP MVC 3 controller -
below group of radio buttons appear on view. able retrieve selected item via simple code
string criteria = filter["criteria"];
however not know how retain selected item. once controller posts view default radio button selected.
<form method="post"> @html.textbox("searchvalue", viewbag.currentfilter string, new { placeholder = "search" }) <input type="image" src="@url.content("~/content/images/filter.bmp")" alt="filter" style="padding-top: 0px;" /> <span class="error" style="clear: both;"> @viewbag.errormessage </span> <a href="#" style="padding-left: 30px;"></a> <br /> <br /> <input type="radio" name="criteria" id="bankname" value="bankname" checked="true"/> <label for="bankname">bank name</label> <input type="radio" name="criteria" id="epurl" value="epurl" /> <label for="epurl">epurl</label> <input type="radio" name="criteria" id="specialnotes" value="specialnotes" /> <label for="specialnotes">special notes</label> <input type="radio" name="criteria" id="email" value="email" /> <label for="email">email</label> <input type="radio" name="criteria" id="dynamicsid" value="dynamicsid" /> <label for="dynamicsid">dynamics id</label> <input type="radio" name="criteria" id="stat" value="stat" /> <label for="fixed">agent id </label> </form>
the answer question wound being incredibly simple. first mistake made not using @html
controls. second using formcollection
input parameter index controller. changing radio buttons following:
@html.radiobutton("criteria", "bankname", true)<span>bank name</span> @html.radiobutton("criteria", "epurl")<span>epurl</span> @html.radiobutton("criteria", "specialnotes")<span>special notes</span> @html.radiobutton("criteria", "email")<span>email</span> @html.radiobutton("criteria", "dynamicsid")<span>dynamics id</span> @html.radiobutton("criteria", "stat")<span>agent id</span>
and signature of index
method in controller this:
public actionresult index(string criteria, string searchvalue)
the selected radio button stayed selected after post back.
Comments
Post a Comment