views:

43

answers:

2

I am using ASP.NET MVC 1. I want to pass an int value to from an action to view. I can use 2 ways.

  1. Use ViewData dictionary.
  2. Define a class to contain the int value.

Other these two, Is there a way to pass the int value to view so that I can get the int value using just Model like

<label><%= Model %></label>
+5  A: 

This works just fine with MVC 2. Don't really know the reason why would you stick with MVC 1. And I also couldn't test it out in MVC1 so I cannot guarantee that it works there.

    public ActionResult Five()
    {
        int five = 5;
        return View(five);
    }


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

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

    <h2>Five</h2>

    <%: Model %>

</asp:Content>
mare
Should work in MVC1 just as well.
Robert Koritnik
+1  A: 

Yes it is. Just define your strong type view like this:

<%@ Page ... Inherits="System.Web.Mvc.ViewPage<int>" %>
Robert Koritnik