문제

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