.NET Routing wala,
man menna me route(url) ekata giyama
http://localhost:50383/Customers/Details
mata menna me wage error ekak enawa,
menna me route ekata giyama menna me wage error ekak enawa
http://localhost:50383/Customers/Details/1
menna mage code tika
CustomerController.cs
Details.cshtml
RoutingConfig.cs
mokada scene eka kiyala balapnko, Stackoverflow dammama un duplicate kiyala ain kala
man menna me route(url) ekata giyama
http://localhost:50383/Customers/Details
mata menna me wage error ekak enawa,
[ArgumentException: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'Vidly.Controllers.CustomersController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters]
menna me route ekata giyama menna me wage error ekak enawa
http://localhost:50383/Customers/Details/1
The model item passed into the dictionary is of type 'Vidly.Models.Customer', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Vidly.Models.Customer]'.
menna mage code tika
CustomerController.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly.Models;
namespace Vidly.Controllers
{
public class CustomersController : Controller
{
// GET: Customers
public ActionResult Index() {
var customers = GetCustomers();
return View(customers);
}
public ActionResult Details(int id)
{
var customer = GetCustomers().SingleOrDefault(c => c.Id == id);
if (customer == null) {
return HttpNotFound();
}
return View(customer);
}
private IEnumerable<Customer> GetCustomers() {
return new List<Customer>
{
new Customer { Id = 1, Name = "John Smith" },
new Customer {Id =2, Name="Mary Kom"}
};
}
}
}
Details.cshtml
Code:
@model IEnumerable<Vidly.Models.Customer>
@{
ViewBag.Title = "Customer";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@if (!Model.Any())
{
<p>Please endter a valid URL</p>
}
else
{
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Customer</th>
</tr>
</thead>
<tbody>
@foreach (var customer in Model)
{
<tr>
<td>@Html.ActionLink(customer.Name, "Details", "Customers", new { id = customer.Id }, null)</td>
<li>
</tr>
}
</tbody>
</table>
}
RoutingConfig.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Vidly
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
mokada scene eka kiyala balapnko, Stackoverflow dammama un duplicate kiyala ain kala


ethakota data type error ekak enawa ++

thanks a lot 