0

ビューに次のものがあれば

@Html.DisplayFor(model => model.sLevelid) 

Controller 
Public actionresult GetName(int id)
{


}

データベース内の別のテーブルでIDが属する名前を取得するlinqクエリを作成できるように、IDをコントローラーに渡すにはどうすればよいですか? 前もって感謝します

4

2 に答える 2

2

あなたの見解では、このようなもの:

// GetName here refers to the name of the action on your controller
@{ Html.RenderAction("GetName", new { id = @Model.sLevelid }); }

次に、コントローラーのアクションは次のようになります。

public PartialViewResult GetName(int id)
{
    var model = // Use Linq to get whatever you need by the id

    return PartialView("_GetName", model);
}

~/Views/Shared/次に、フォルダーに部分ビューを作成し、名前を付け_GetName.cshtmlます。そのビューは次のようになります。

@model TheTypeOfModelGetNameReturns

<div>@Model.SomeProperty</div>
于 2013-11-08T14:21:20.603 に答える