Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC2 issues when edit an item on an textboxfor
    primarykey
    data
    text
    <p>i have this model on mvc:</p> <pre><code>public class User { public string Name { get; set; } public IList&lt;string&gt;RelatedTags { get; set; } } </code></pre> <p>And the following typed view (user) to edit an add a user (AddEdit.aspx view):</p> <pre><code>&lt;div&gt; &lt;%: Html.LabelFor(e =&gt; e.Name)%&gt; &lt;%: Html.TextBoxFor(e =&gt; e.Name)%&gt; &lt;%: Html.ValidationMessageFor(e =&gt; e.Name)%&gt; &lt;/div&gt; &lt;div&gt; &lt;%: Html.LabelFor(e =&gt; e.RelatedTags)%&gt; &lt;%: Html.TextBoxFor(e =&gt; e.RelatedTags)%&gt; &lt;%: Html.ValidationMessageFor(e =&gt; e.RelatedTags)%&gt; &lt;/div&gt; </code></pre> <p>For other hand i have a "RelatedTags" field. I needed (on action controller side) a List of tags related with the user that im adding. For this reason i created a Custom model binder (to take the string of the textbox and pass it as List):</p> <pre><code>public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { List&lt;string&gt; listoftags = bindingContext.ValueProvider.GetValue("RelatedTags").AttemptedValue.Split(',').ToList&lt;string&gt;(); return listoftags; } </code></pre> <p>Actually i can use the AddEdit.aspx to add a new user (on controller side im getting a List of related tags, but when i edit a user i dont know where i can convert this List to comma string, and either i dont know should change these lines on the view:</p> <pre><code>&lt;div&gt; &lt;%: Html.LabelFor(e =&gt; e.RelatedTags)%&gt; &lt;%: Html.TextBoxFor(e =&gt; e.RelatedTags)%&gt; &lt;%: Html.ValidationMessageFor(e =&gt; e.RelatedTags)%&gt; &lt;/div&gt; </code></pre> <p>By the moment, just in case, i created an extension method for the IList:</p> <pre><code>public static class Extensions { public static string ToCommaString&lt;T&gt;(this IList&lt;T&gt; input) { StringBuilder sb = new StringBuilder(); foreach (T value in input) { sb.Append(value); sb.Append(","); } return sb.ToString(); } } </code></pre> <p>Could you give me any help for when im editing a user see in the input field a string separated with commas with all the elements of the list?</p> <p>Thanks a lot in advance.</p> <p>Best Regards.</p> <p>Jose.</p>
    singulars
    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.
    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