2017-12-08 15 views
-1

私は編集ボタンをクリックします。ドロップダウン値は来ていませんが、ViewBag.DomainIDに値がありますが、表示されていません。編集ボタンをクリックするとドロップダウンの値がmvcで表示されないのですか?

[Authorize] 
     [MyExceptionHandler] 
     public ActionResult EditModules(int id) 
     { 
      EditDomain_Bind(); 
      userType type = new userType(); 
      var ModID = type.GetEditRoleModulesViews(id).Find(Emp => Emp.ModuleID == id); 
      int domainID = ModID.DomainID; 
      AccountContext db = new AccountContext(); 
      string selected = (from sub in db.domain 
           where sub.DomainID == domainID 
           select sub.DomainName).First(); 
      ViewBag.DomainID = new SelectList(db.domain, "DomainID", "DomainName", selected); 

      return View(ModID); 
     } 

Cs.HTML:

<div class="col-lg-4"> 
          <fieldset class="form-group"> 
           <label class="form-label" for="exampleInput">Domain Name</label> 
           @Html.DropDownList("DomainID") 
           @Html.ValidationMessageFor(model => Model.DomainID, null, new { @style = "color: red" }) 
          </fieldset> 
         </div> 

モデル:それはThe specified cast from a materialized 'System.Int64' type to the 'System.Int32' type is not valid.

コントローラを示し

public DbSet<Domain> domain { get; set; } 
    public class Domain 
    { 
     [Key] 
     public int DomainID { get; set; }  
     public string DomainName { get; set; } 

    } 
+1

データベースのデータ型がモデルと同じですか。 –

+0

私のPIC –

+0

@mjwills https://ibb.co/kpp35Gそれをチェック –

答えて

1

問題は、あなたのようにDomainIDが定義されていることである。

C#では

ですが、bigint(つまり、 long)をデータベースに格納します。

public long DomainID { get; set; } 

し、同様に他のすべてのintDomainIDの参照を変更します。したがって、代わりにあなたが使用する必要があります。例:

long domainID = ModID.DomainID; 
+1

働いてくれてありがとう –

+0

私は1つのヘルプのドロップダウンID値のみを取得する必要があります..私はドロップダウンリストでDomainNameを取得したい –

+0

その@IvinRajの新しい質問を作成することをお勧めします。 – mjwills

関連する問題