In this line:
@Html.ActionLink("Reply", "BlogReplyCommentAdd", "Blog",
new { blogPostId = blogPostId, replyblogPostmodel = Model,
captchaValid = Model.AddNewComment.DisplayCaptcha })
I get the following runtime error on blogPostId:
The parameters dictionary contains a null entry for parameter 'blogPostId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult BlogReplyCommentAdd(Int32, Nop.Web.Models.Blogs.BlogPostModel, Boolean)' in 'Nop.Web.Controllers.BlogController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
I have already assign a value for this on top such as
@{
var blogPostId = Model.Id;
}
My Controller:
public ActionResult BlogReplyCommentAdd(int blogPostId, BlogPostModel model, bool captchaValid)
{}
Am I doing something wrong? Please give me an example.
The problem must be with the value Model.Id which is null. You can confirm by assigning a value, e.g
If the error disappers, then u need to make sure that your model Id has a value before passing it to the view
You are using a wrong overload of the
Html.ActionLink
helper. What you think isrouteValues
is actuallyhtmlAttributes
! Just look at the generated HTML, you will see that this anchor's href property doesn't look as you expect it to look.Here's what you are using:
and here's what you should use:
Also there's another very serious issue with your code. The following routeValue:
You cannot possibly pass complex objects like this in an ActionLink. So get rid of it and also remove the
BlogPostModel
parameter from your controller action. You should use theblogPostId
parameter to retrieve the model from wherever this model is persisted, or if you prefer from wherever you retrieved the model in the GET action:As far as your initial problem is concerned with the wrong overload I would recommend you writing your helpers using named parameters:
Now not only that your code is more readable but you will never have confusion between the gazillions of overloads that Microsoft made for those helpers.
I have to pass two parameters like:
This way:
will generate this url
I used a workaround method by merging parameter two in parameter one and I get what I wanted:
And I get :