Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use an editor template to achieve this.</p> <p>the editor template will allow you to loop through a list of social networks in your main view and use the @Html.EditorFor helper to render out your dropdown lists and make model binding easy.</p> <p>To start with your model should represent a single Social Network</p> <p>In your model you need properties to contain the dropdown list values, and a property for the selected value. You'll also need a property to contain the SocialNetworkUsername</p> <pre><code>public IEnumerable&lt;SelectListItem&gt; SocialNetworks { get; set; } public string SelectedSocialNetwork { get; set; } public string SocialNetworkUserName { get; set; } </code></pre> <p>To make your editor template add a new folder /Views/Shared/EditorTemplates</p> <p>In the EditorTemplates folder create a new view with the name MyClass (or whatever your model class name is)</p> <p>You need to follow these naming conventions as there is no other configuration required for the editor template to work.</p> <p>In MyClass.cshtml you need to allow editing of a single social network</p> <pre><code>@model MyModel @Html.DropDownListFor(m =&gt; m.SelectedSocialNetwork, Model.SocialNetworks) @Html.TextBoxFor(m =&gt; m.SocialNetworkUserName) </code></pre> <p>Then in your main view you use a List of MyModel as the model for the view and use a for loop to render out your editor templates.</p> <pre><code>@model List&lt;MyModel&gt; @using(Html.BeginForm()) { for (var i = 0; i &lt; Model.Count; i++) { Html.EditorFor(Model[i]) } } </code></pre> <p>In your controller just change your action method parameter to accept a List of MyClass and model binding should just magically work ;)</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.
    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