Question

J'ai cela sur moi et cela fonctionne bien, persistant du pays choisi:

<%: Html.DropDownListFor(model => model.CountryId, Model.CountryList ,"Select Country") %>

Cependant, quand je crée un modèle d'éditeur pour cela, le pays sélectionné ne persistent pas

Alors, je change mon avis actuel à ceci:

 <%: Html.EditorFor(model => model.CountryId,new { countries = Model.CountryList}) %>

Alors je crée mon modèle d'éditeur comme ceci:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Int64?>" %>
<%= Html.DropDownList(
        String.Empty /* */, 
        (SelectList)ViewData["countries"], 
        Model
    )
%>
Était-ce utile?

La solution

Je voudrais essayer quelque chose comme ceci:

code en vue parent:

 <% Html.RenderPartial("YourPartialView", Model) %>

code en mode éditeur:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ModelFromParent>" %>
<%= Html.DropDownList(
    String.Empty /* */, 
    new SelectList(Model.Countries,"Id", "Title"), 
    "Select Country"
)

%>

Je ne compile pas cela. Mais vous avez l'idée générale.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top