Home > DeveloperSection > Forums > ASP MVC3 ActionLink not rendering variables
Royce Roy
Royce Roy

Total Post:149

Posted on    April-05-2013 1:38 AM


 1 Reply(s)
 1364  View(s)
Rate this:
I am trying to use an ASP MVC3 action link to navigate to another view (same controller). The view is attached to a model that uses a compound key for its 

primary key. Below is the action link as it's written on the view

@Html.ActionLink("Edit Agent", "AgentEdit", "BankListMasterController", 
                                                new { @agentId = int.Parse(item.AgentId), @id = item.ID})
However when this is rendered it renders as the following

Which obviously throws an error:

The parameters dictionary contains a null entry for parameter 'agentId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ViewResult AgentEdit

(Int32, Int32)' in 'Monet.Controllers.BankListMasterController'. An optional parameter must be a reference type, a nullable type, or be declared as an 

optional parameter.
Parameter name: parameters
Here is the controller method for good measure:

    public ViewResult AgentEdit(int agentId, int id)
        string compare = agentId.ToString();

        BankListAgentId agent = (from c in db.BankListAgentId
                                 where c.ID == id &&
                                 select c).Single();

        return View("AgentEdit", agent);


Total Post:604

Posted on    April-05-2013 8:13 AM

Hi Royce!

try action link as below

@Html.ActionLink("Edit Agent", "AgentEdit", "BankListMasterController",
    new { agentId = int.Parse(item.AgentId), id = item.ID}, null)

Don't want to miss updates? Please click the below button!

Follow MindStick