Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC A problem with passing a string object into View

Tags:

asp.net-mvc

I want to pass a string object into a View:

 <%@ Page Title="" Language="C#" 
     MasterPageFile="~/Views/Shared/Site.Master"
     Inherits="System.Web.Mvc.ViewPage<String>" %>

   <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

          <h2><%=Model %></h2>

   </asp:Content>

When I try this:

 return View("SomeView", "stringToPass");

the error occurs: The view 'SomeView' or its master was not found.

but, when I change the return to

return View("SomeView");

everything works fine. So how to pass that string ?

like image 586
Tony Avatar asked Sep 14 '10 14:09

Tony


1 Answers

its confusing it with another overload of View(), do:

return View("SomeView", (object)"stringToPass");
like image 98
eglasius Avatar answered Oct 20 '22 15:10

eglasius