当前位置: 动力学知识库 > 问答 > 编程问答 >

Passing SelectList along with model in ASP.Net Core MVC

问题描述:

My AppUser class contains following property

 public string UserName { get; set; }

public string Email { get; set; }

public Cities City { get; set; }

where Cities is an enum contains cities of AppUsers.

While i creating CRUD action methods for this user, i want to populate these cities as dropdownlist in my Views(I can convert enum to SelectList).

I tried to create a Viewmodel containing Cities enum as property, but for my edit action i am using direct AppUser as model. Here i can't populate them as Dropdownlist in Edit view.

In short, Without adding Cities to the user(viewmodel) class how can we pass SelectList to View. Tried Tempdata, Viewdata Viewbag but they disappear when app getting validation errors.

分享给朋友:
您可能感兴趣的文章:
随机阅读: