質問

Basically my action return a viewModel with a List - each language has anID and a title

So in my view I have the following fropdown

@Html.DropDownList("Languages", new SelectList(Model.lstLanguages, "LanguageID", "Name"), "SELCT  LANGUAGE----->",new { id = "ddlLanguages" })

SOmy question is - as I will have other views with dropdown and I will save in a session the id of the chosen language so when the user is redirected back by to this view

I want to be able to say something like this

ddllanguages.SelectedItem = @HttpContext.Current.Session["langID"]
役に立ちましたか?

解決

@Html.DropDownList(
    "Languages", 
    new SelectList(
        Model.lstLanguages, 
        "LanguageID", 
        "Name",
        Session["langID"]
    ), 
    "<-----SELECT  LANGUAGE----->",
    new { id = "ddlLanguages" }
)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top