I want to know what is the best way to display check boxes in asp.net mvc 5 application.
Attempt 1:
@Html.RadioButton("SearchBy", "Name", true) <text> Name </text>
@Html.RadioButton("SearchBy", "Location") <text> Location</text>
[HttpPost]
public ActionResult Create(CoverLetterViewModel viewModel, string searchBy)
{//somecode}
Attempt 2:
//prop
public string SelectedRoleType { get; set; }
//view
<label>
@Html.RadioButtonFor(m => m.SelectedRoleType, "JobSeeker", new { @class = "js-radio", id = "" })
<span>Job Seeker</span>
</label>
<label>
@Html.RadioButtonFor(m => m.SelectedRoleType, "Referrer", new { @class = "js-radio", id = "" })
<span>Referrer</span>
</label>
//controller action
[HttpPost]
public ActionResult Create(CoverLetterViewModel viewModel)
{//somecode}
Attempt 3: Now suppose I have 10 radiobutton, is there any efficient way to create radiobutton. I mean suppose I have a list of radiobuttonitem, Something like below
public List<SOME RADIBUTTON ITEM> radiobuttonlist {get;set;}
Question:
Can we somehow display radiobuttonsame way we handle List of Dropdown Item . Can we somehow avoid hardcoding "Referrer"
AND "JobSeeker"
text in view file.
Aucun commentaire:
Enregistrer un commentaire