Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:29:15+00:00 2026-06-09T12:29:15+00:00

I trying resolve this problem during this two days. Unfortunately I am not able

  • 0

I trying resolve this problem during this two days. Unfortunately I am not able to do it. I don`t understand why my “form” send null values to some class. Have you hot idea what I have to do? Really this problem is nervous me.

The parameters dictionary contains a null entry for parameter
‘Id_tow’ of non-nullable type ‘System.Int32’ for method
‘System.Web.Mvc.RedirectToRouteResult AddToCart(Int32, System.String)’
in ‘SportsStore.WebUI.Controllers.CartController’. An optional
parameter must be a reference type, a nullable type, or be declared as
an optional parameter. Parameter name: parameters Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.

Exception Details: System.ArgumentException: The parameters dictionary
contains a null entry for parameter ‘Id_tow’ of non-nullable type
‘System.Int32’ for method ‘System.Web.Mvc.RedirectToRouteResult
AddToCart(Int32, System.String)’ in
‘SportsStore.WebUI.Controllers.CartController’. An optional parameter
must be a reference type, a nullable type, or be declared as an
optional parameter. Parameter name: parameters

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Here is this form:

@model SportsStore.WebUI.Models.SomeView
@using SportsStore.WebUI.HtmlHelpers
@using SportsStore.WebUI.Controllers
@using SportsStore.Entities

@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>List</h2>

@foreach (var p in Model.Towar)
{
<div class="item">
<h3>@p.Nazwa</h3>
@p.Opis

@using(Html.BeginForm("AddToCart", "Cart")) {
@Html.HiddenFor(x => @p.Id_tow)
@Html.Hidden("returnUrl", Request.Url.PathAndQuery)
<input type="submit" value="+ Add to cart" />
}

<h4>@p.Cena.ToString("c")</h4>
</div>
}

<h2>List</h2>

@foreach (var b in Model.Kategorie)
{
<div class="item">
<h3>@b.Nazwa</h3>
</div>
}

<div class="pager">
@Html.PageLinks(Model.PagingInfo, x => Url.Action("List",
new {page = x, category = Model.CurrentCategory}))
</div>

In my opinion is show correct values but send null to class (HTML source)

<div class="item">
<h3>Piłka</h3>
Piłka Firmy Nike

<form action="/Cart/AddToCart" method="post"><input data-val="true" data-val-number="The field Id_tow must be a number." data-val-required="The Id_tow field is required." id="p_Id_tow" name="p.Id_tow" type="hidden" value="1" /><input id="returnUrl" name="returnUrl" type="hidden" value="/" /><input type="submit" value="+ Add to cart" />
</form>
<h4>59,80 zł</h4>
</div>

Part of Controller Cart which get nulls values:

public RedirectToRouteResult AddToCart(int Id_tow, string returnUrl)
            {
                Towar product = repository.Towar
                .FirstOrDefault(p => p.Id_tow == Id_tow);
                if (product != null)
                {
                    GetCart().AddItem(product, 1);
                }

                return RedirectToAction("Index", new { returnUrl });
            }

If I will put my values everything working correct but of course this not fix a problem

public RedirectToRouteResult AddToCart(int Id_tow = 1, string returnUrl = "www.gmail.com")
            {
                Towar product = repository.Towar
                .FirstOrDefault(p => p.Id_tow == Id_tow);
                if (product != null)
                {
                    GetCart().AddItem(product, 1);
                }

                return RedirectToAction("Index", new { returnUrl });
            }

This fix problem if not your help I will be not able to fix this. Thanks

@foreach (var p in Model.Towar)
{
<div class="item">
<h3>@p.Nazwa</h3>
@p.Opis

@{
    int Id_tow = @p.Id_tow;
}


@using(Html.BeginForm("AddToCart", "Cart")) {
@Html.HiddenFor(x => Id_tow)
@Html.Hidden("returnUrl", Request.Url.PathAndQuery)
<input type="submit" value="+ Add to cart" />
}

<h4>@p.Cena.ToString("c")</h4>
</div>
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:29:17+00:00Added an answer on June 9, 2026 at 12:29 pm

    You could replace

    public RedirectToRouteResult AddToCart(int Id_tow, string returnUrl)
                {
                    Towar product = repository.Towar
                    .FirstOrDefault(p => p.Id_tow == Id_tow);
                    if (product != null)
                    {
                        GetCart().AddItem(product, 1);
                    }
    
                    return RedirectToAction("Index", new { returnUrl });
                }
    

    with

    public RedirectToRouteResult AddToCart(Towar tow, string returnUrl)
                {
                    Towar product = repository.Towar
                    .FirstOrDefault(p => p.Id_tow == tow.Id_tow);
                    if (product != null)
                    {
                        GetCart().AddItem(product, 1);
                    }
    
                    return RedirectToAction("Index", new { returnUrl });
                }
    

    Or you could use Html.Hidden("Id_tow", @p.Id_tow) but this would not be recommended as it creates a bit of a brittle dependency between the View and the Controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent the last few hours trying to resolve this problem, and I'm not
Been trying to resolve this problem with a rewrite rule that assigns a subdomain
I found this thread while trying to resolve my issue unfortunately this I can't
please help me resolve this problem: There is an ambient MSMQ transaction. I'm trying
I'm becoming mad trying to figure out how to resolve this task. My goal
So, I'm having a hard time trying to resolve a college problem... What I
I'm a noob with C++, but I need to resolve this problem ASAP. I'm
I am trying to resolve a problem with a set of packages that apparently
I am not sure if this is possible, but I'm trying to find a
This fails with an ObjectDisposedException when trying to assert: [Test] public void Resolve_SingletonAndDisposeChildContainer_ShouldNotDisposeSingleton() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.