MVC 3 文字列をビューのモデルとして渡すことができませんか? 質問する

MVC 3 文字列をビューのモデルとして渡すことができませんか? 質問する

ビューに渡されたモデルに奇妙な問題があります

コントローラ

[Authorize]
public ActionResult Sth()
{
    return View("~/Views/Sth/Sth.cshtml", "abc");
}

ビュー

@model string

@{
    ViewBag.Title = "lorem";
    Layout = "~/Views/Shared/Default.cshtml";
}

エラーメッセージ

The view '~/Views/Sth/Sth.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Sth/Sth.cshtml
~/Views/Sth/abc.master  //string model is threated as a possible Layout's name ?
~/Views/Shared/abc.master
~/Views/Sth/abc.cshtml
~/Views/Sth/abc.vbhtml
~/Views/Shared/abc.cshtml
~/Views/Shared/abc.vbhtml

単純な文字列をモデルとして渡すことができないのはなぜですか?

ベストアンサー1

はい、正しい使い方をすれば可能です過負荷:

return View("~/Views/Sth/Sth.cshtml" /* view name*/, 
            null /* master name */,  
            "abc" /* model */);

おすすめ記事