I am writing code that will create an object client and show it
Class1.cs is the model I am using:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication4.Models
{
public class Class1
{
public class Customer
{
public int Id { set; get; }
public string CustomerCode { set; get; }
public double Amount { set; get; }
}
}
}
in the DefaultController section I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication4.Models ;
namespace WebApplication4.Models
{
public class Default1Controller : Controller
{
public ActionResult Index()
{
Class1.Customer ob = new Class1.Customer();
ob.Id = 1001;
ob.CustomerCode = "C001";
ob.Amount = 900.23;
return View(ob);
}
}
}
I right-clicked ActionResult and added a view with the following code:
@model WebApplication4.Models.Class1
@{
ViewBag.Title = "Index";
}
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<div>
The customer id is: <% = | Model.Id %> < br/>
The customer Code is: <% = | Model.CustomerCode %> < br/>
The customer Amount is: <% = | Model.Id %> < br/>
</div>
</body>
</html>
When I run the code, I get:
Exception Details: System.InvalidOperationException: The model element passed to the dictionary is of type WebApplication4.Models.Class1 + Customer, but this dictionary requires a model element of type WebApplication4.Models.Class1.
ok, I selected a class in class Class1.cs,
so now it only talks about the public class client.
and I also changed the namespace WebApplication4.Models
to the WebApplication4.Controller namespace in DefaultController1.cs,
Index.cshtml,
Class1 WebApplication4.Models