0

次のような文字列からのレンダー ビューが必要です。

public class Controller : System.Web.Mvc.Controller
{
    public ViewResult ViewList()
    {
        string html = "<div id=\"contentView\">";
        html += Title(null);
        html += GridControls(null);
        html += FilterControls(null);
        html += Grid(null, new Sibi.Seg.User().List(pagina));
        html += "</div>";
        return View(html );
    }

}

次に、コントローラーで View() を返すときにこの文字列をレンダリングする必要があります。それを参照してください。

public ActionResult Index()
{
      return ViewList();
}
4

1 に答える 1

1

コントローラーのContentメソッドを使用できます。コードは次のようになります。

public ActionResult ViewList()
{
    string html = "<div id=\"contentView\">";
    html += Title(null);
    html += GridControls(null);
    html += FilterControls(null);
    html += Grid(null, new Sibi.Seg.User().List(pagina));
    html += "</div>";
    return Content(html, "text/html");
}

または、内部コードを静的クラスに移動して、mvc ビューから静的メソッドを呼び出すこともできます。次に例を示します。

@{
    Layout = null;
}
<div id="contentView">
    @(Html.Raw(StaticMethods.Title(null)))
    @(Html.Raw(StaticMethods.GridControls(null)))
    @(Html.Raw(StaticMethods.FilterControls(null)))
    @(Html.Raw(StaticMethods.Grid(null, new Sibi.Seg.User().List(pagina))))
</div>

これら 2 つの解決策のいずれでも同じ結果が得られます。

于 2013-11-12T18:29:10.177 に答える