C# 如何将我的用户对象数据传递到ASPX页面?
我只是想在ASP.net(ASPX)中做一些非常简单的事情,但它似乎不起作用 我有以下类/模型、视图和控制器: Users.csC# 如何将我的用户对象数据传递到ASPX页面?,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我只是想在ASP.net(ASPX)中做一些非常简单的事情,但它似乎不起作用 我有以下类/模型、视图和控制器: Users.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ASPWebsite.Models { public class Users { private string firstName;
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;
}
}
}
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();
}
}
}
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>
如您所见,我创建了一个名为foobar的用户,并将其传递给视图,但当我运行它时,它不会显示名称。有什么问题吗 尝试
nvm,忘记删除;最后谢谢