Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 Can't pass string as a View's model?

I have a strange problem with my model passed to the View

Controller

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

View

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

The error message

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 

Why can't I pass a simple string as a model ?

like image 378
Tony Avatar asked Mar 21 '12 10:03

Tony


1 Answers

Yes you can if you are using the right overload:

return View("~/Views/Sth/Sth.cshtml" /* view name*/,              null /* master name */,               "abc" /* model */); 
like image 142
nemesv Avatar answered Sep 21 '22 06:09

nemesv