Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding foreach for @html.checkboxfor

I am developing an application using MVC. I had a requirement where I have to display checkbox for a list.

I was going through different posts for doing this, one of them is the use of avoiding foreach for looping and making use of @html.editorfor() as described in the answer by Darwin dimitrov here:

This answer works fabulously fine, but I have a clarification , it is:

  1. In the same view I have 2 requirements , the one with checkboxfor and the other one with radiobuttonfor So, If I am using

    <div>@Html.EditorFor(x => x.RoleAccess)</div>

How do I write the (~/Views/Shared/EditorTemplates/RoleAccessViewModel.cshtml) to serve for checkboxfor for one requirement , and the other one for @radiobuttonfor .

Wont this approach be hardcoded which will always render the RoleAccessViewModel.cshtml whenever EditorFor(x => x.RoleAccess) is used?Please execuse me If I have used any technical terms wrong way,as I still a novice in mvc.

like image 905
Jquery Developer Avatar asked Oct 21 '22 03:10

Jquery Developer


1 Answers

The EditorFor method has an overload that accepts a template name as argument. I think that solves your problem if I understand it correctly. See http://msdn.microsoft.com/en-us/library/ee407414%28v=vs.118%29.aspx

like image 110
chris Avatar answered Oct 23 '22 03:10

chris