I have a bit of a weird issue with a record display. If a user enters a bar-code numeric (int) value into a URL, I'm supposed to show the details of the record linked to that bar-code. At one time, GUIDs (CodeId GUID PK) were used for the bar-codes, but now we are adding a new Int field (SerialId IDENTITY Int) to keep track of the actual bar-code value; we're not allowed to change the CodeId field on the table (which called Code), so this leads to my odd issue. I've looked around, and this QueryString id parameter not being used is the closest that I can find to addressing what's happening with me.
My Routing is perfectly normal
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Model is normal
public DbSet<Code> Codes { get; set; }
public partial class Code
{
public System.Guid CodeId { get; set; }
public int SerialId { get; set; }
public string Title { get; set; }
public string BarCodeDescr { get; set; }
public System.DateTime CreateDate { get; set; }
public System.DateTime LastActivityDate { get; set; }
}
My controller worked just fine when things were a GUID, and the Id mapped to CodeId (the table's PK) etc.
public ViewResult BarCode(Guid id)
{
Code code = db.Codes.Find(id);
return View(code);
}
Now I'm trying to do something more like this:
public ViewResult BarCode(int serialid)
{
Code code = db.Codes.Find(serialid);
return View(code);
}
or this...
public ActionResult QRCode(int serialid)
{
ViewData["SerialId"] = serialid;
return View(db.Codes.Where(x => x.SerialId == serialid).ToList());
}
...only all my attempts lead to the same error:
The parameters dictionary contains a null entry for parameter 'serialid'
of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult
BarCode(Int32)' in 'MyProject.Controllers.HomeController'. An optional parameter
must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
What am I doing wrong? It's not ideal to have my view return a record based on searching for a specific SerialId instead of the CodeId, but it should be do-able, right?