2013-07-14 2 views
0

저는 ASP.net (ASPX)에서 정말 단순한 작업을하려고하고 있습니다. 작동하지 않는 것 같습니다.내 사용자 개체 데이터를 ASPX 페이지로 전달하는 방법은 무엇입니까?

나는 다음과 같은 클래스/모델,보기 및 컨트롤러가 있습니다

Users.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace ASPWebsite.Models 
{ 
    public class Users 
    { 
     private string firstName; 
     private string lastName; 

     public Users(string firstName, string lastName) 
     { 
      this.firstName = firstName; 
      this.lastName = lastName; 
     } 

     public string GetFirstName() 
     { 
      return this.firstName; 
     } 

     public string GetLastName() 
     { 
      return this.lastName; 
     } 
    } 
} 

Index.aspx

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
    Index 
</asp:Content> 

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

<h2>Index</h2> 

<h2><%Model.GetFirstName();%></h2> 

</asp:Content> 

HomeController.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

using ASPWebsite.Models; 

namespace ASPWebsite.Controllers 
{ 
    public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      ViewBag.Message = "Welcome to ASP.NET MVC!"; 

      var user = new Users("foo", "bar"); 

      return View(user); 
     } 

     public ActionResult About() 
     { 
      return View(); 
     } 
    } 
} 

보시다시피 이름이 foo 바인 사용자를 작성하여보기에 전달했지만 실행하면 이름이 표시되지 않습니다. 무엇이 잘못 되었습니까 ??

답변

3

지금은 컴파일러 오류 메시지를 받고 있어요

+0

<h2><%: Model.GetFirstName() %></h2>을보십시오 : CS1026 :) – Danny

+0

NVM 예상을의를 삭제하는 것을 잊었다; 결국 감사합니다. – Danny

관련 문제