私は MVC を初めて使用し、このビデオを見てサンプル アプリケーションを作成しています。モデルとコントローラーでクラスを作成しました。ビューを介してクラス プロパティにアクセスしようとすると、書き込み中であってもアクセスできません。 <%=Model.Id %> のようなビューでは、サーバー側のスクリプトの場合のように角括弧が黄色でマークされていません。問題がどこにあるかを見つけることができませんか?
モデルのクラス Customer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcCustomer.Models
{
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public double Amount { get; set; }
}
}
そしてコントローラーは
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcCustomer.Models;
namespace MvcCustomer.Controllers
{
public class LoadCustomerAndDisplayController : Controller
{
//
// GET: /LoadCustomerAndDisplay/
public ActionResult Index()
{
Customer customer = new Customer();
customer.Name = "Devesh";
customer.Amount = 22.9;
customer.Id = 1;
return View(customer);
}
}
}
そして私の強く型付けされたビュー(IntelliSenseも機能していません)は
@model MvcCustomer.Models.Customer
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
The Customer id is: <%= Model.Id %>
</div>
</body>
</html>