Steve
Steve

Reputation: 923

mvc 3 (maybe earlier) ViewData on page not been substituted its value

I do have one project in this solution where this works.

This project was started by copying that and renaming it.

This is in the controller:

    public ActionResult Index(User user)
    {
        ViewData["debug"] = "hi ya!";
        return View();
    }

This is the page (index.aspx ~ this isn't cshtml):

<%@ Register Assembly="T30" TagPrefix="a" Namespace="Prj.T30.Html" %>
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/template/MVC.master" Title="Material Moves" %>
<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
<div>
    <input type="text" value="" id="Text1" />
    <br />
    ViewData["debug"]
</div>
</asp:Content>

The page in the browser is the literal

"ViewData["debug"]"

Why isn't it what I should be able to expect?

"Hi ya!"

Thanks for your time, thoughts, and well wishes.

Upvotes: 0

Views: 49

Answers (2)

this.hart
this.hart

Reputation: 328

   <%@ Register Assembly="T30" TagPrefix="a" Namespace="Prj.T30.Html" %>
   <%@ Page Language="C#" AutoEventWireup="true"                   
    MasterPageFile="~/template/MVC.master" Title="Material Moves" %>
   <asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
   <div>
<input type="text" value="" id="Text1" />
<br />
@string vData= ViewData["debug"];
 @vData;
</div>
 </asp:Content>

Upvotes: 1

Steve
Steve

Reputation: 923

Thanks to @stuartd for the much needed nudge.

For the @ directives ~ load the ViewPage class in the Inherits attribute:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/template/MVC.master" Title="really moving stuff man" %>

For the page content:

<% =ViewData["debug"] %>

Done.

Upvotes: 1

Related Questions