Hello
I am new to asp.net mvc2 ,but i have experience in ASP.net c#.Now using the tutorial posted on Codeproject.
now am getting an error when passing values from controller to view
Server Error in '/' Application.
The model item passed into the dictionary is of type 'MyFirstHelloWorld.Models.Customer', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MyFirstHelloWorld.Models.Customer]'.
Controller Code
----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyFirstHelloWorld.Models;
namespace MyFirstHelloWorld.Controllers
{
public class CustomerController : Controller
{
public ActionResult Index()
{
return View();
}
public ViewResult DisplayCustomer()
{
Customer cs = new Customer();
cs.Code = "12";
cs.Name = "Salil Sasidharan";
cs.Amount = 23500;
return View("DisplayCustomer", cs);
}
}
}
Model Code
-----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyFirstHelloWorld.Models
{
public class Customer
{
private string _Code;
private string _Name;
private double _Amount;
public string Code
{
set
{
_Code = value;
}
get
{
return _Code;
}
}
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
public double Amount
{
set
{
_Amount = value;
}
get
{
return _Amount;
}
}
}
}
View Code
----------
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { }) %> |
<%: Html.ActionLink("Details", "Details", new { })%> |
<%: Html.ActionLink("Delete", "Delete", new { })%>
</td>
<td>
<%: item.Code %>
</td>
<td>
<%: item.Name %>
</td>
<td>
<%: String.Format("{0:F}", item.Amount) %>
</td>
</tr>
<% } %>
</table>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>