Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net-mvc3 EditorFor template name issue
    primarykey
    data
    text
    <p>i'm having a strange issue regarding the editorFor helper from MVC3. Here's the thing: i'm trying to display a checkboxList and it works if i don't call explicity the template name. However if i try to use the template name, it throws an exception saying that i'm trying to pass a Generic list when i should simply pass my viewModel. I'll show some code to make it more understandable:</p> <p>ViewModel</p> <pre><code>public class ChkViewModel { public string ContractName {get;set;} public string Contract {get;set;} public bool Checked {get;set;} } </code></pre> <p>The EditorFor Template (it is called ContractTemplate)</p> <pre><code>@model Models.ChkViewModel &lt;p&gt; @Html.HiddenFor(x =&gt; x.Contract ) @Html.LabelFor(x =&gt; x.ContractName , Model.ContractName ) @Html.CheckBoxFor(x =&gt; x.Checked, new { @class = "chkContract" }) &amp;nbsp; &lt;/p&gt; </code></pre> <p>Excerpt from my view</p> <pre><code>&lt;div id="contractContainer"&gt; @Html.EditorFor(item=&gt;item.ContractList) &lt;/div&gt; </code></pre> <p>This works fine. But it try to do this:</p> <pre><code>&lt;div id="contractContainer"&gt; @Html.EditorFor(item=&gt;item.ContractList, "ContractTemplate") &lt;/div&gt; </code></pre> <p>It throws the <code>InvalidOperationException</code> saying that i have to pass a simple ChkViewModel and not a GenericList ChkViewModel.</p> <p>I'm only asking this because i've tried to create another checkboxlist and i couldn't make it work (not even display the checkboxes) and when i tried to set the template name, so that i could at least see the checkboxes, it thrown that error.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload