c# - Mvc identity: Adding UserId to another table -


i have model called sammanhang

[key] public int sammanhangsid { get; set; }  public string namn { get; set; } 

and want include id of users foreign key can dropdown-list of users in database.

i attepmted doing

public class sammanhang {     [key]     public int sammanhangsid { get; set; }      public string namn { get; set; }      public string userid { get; set; }     [foreignkey("userid")]     public virtual applicationuser applicationuser { get; set; } } 

and inside identitymodels

public class applicationuser : identityuser {     public virtual sammanhang sammanhang { get; set; } } 

but without no success, there anyway achieve user dropdownlist?

try using selectlistitem , anonymous types if needs setup quickly.

  @html.dropdownlist("users", new list<selectlistitem> { new selectlistitem { text = "john" }, new selectlistitem { text = "frank" }, new selectlistitem { text = "joe" } }, "select user") 

or using existing model,

@using (html.beginform()) {      <fieldset>          <legend>select users</legend>          <div class="editor-field">              @html.listbox("users", viewbag.userslist multiselectlist              )          </div>          <p>              <input type="submit" value="save" />          </p>      </fieldset> 

more information at: http://www.asp.net/mvc/overview/older-versions/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -