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 8462569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:12:00+00:00 2026-06-10T14:12:00+00:00

I have a dictionary being used. And when the submit is hit, how do

  • 0

I have a dictionary being used. And when the “submit” is hit, how do I also pass the dictionary with the values in it to the [HttpPost] controller method?
Currently in the [HttpPost] method, the DummyDictionary is empty, how would I fix this?

Thanks!

MODEL

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using DummyMVC.Objects;

    namespace DummyMVC.Models
    {
        public class TheModel
        {
            public TheObject Obj { get; set; }
            public Dictionary<string, TheObject> DummyDictionary { get; set; }
        }
    }

CONTROLLER

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using DummyMVC.Models;
    using DummyMVC.Objects;

    namespace DummyMVC.Controllers
    {
        public class DummyController : Controller
        {
            //
            // GET: /Dummy/
            [HttpGet]
            public ActionResult Index()
            {
                TheModel m = new TheModel();
                m.Obj = new Objects.TheObject();
                TheObject a_obj = new TheObject();
                a_obj.Name = "Joe";
                m.DummyDictionary = new Dictionary<string, Objects.TheObject>();
                m.DummyDictionary.Add("VT", a_obj);
                return View(m);
            }

            [HttpPost]
            public ActionResult Index(TheModel model)
            {
                // HERE THE DICTIONARY is EMPTY, where all the form values should exist.
                string test = "";
                return View(model);
            }

        }
    }

VIEW

    @model DummyMVC.Models.TheModel

    @{
        ViewBag.Title = "Index";
    }

    <h2>Index</h2>

    @using (Html.BeginForm())
    {
        @Html.HiddenFor(m => m.DummyDictionary);
        @Html.LabelFor(m => m.DummyDictionary["VT"].Name)
        @Html.TextBoxFor(m => m.DummyDictionary["VT"].Value)<br />
        @Html.TextBoxFor(m => m.DummyDictionary["VT"].Token, new { @Value = Model.DummyDictionary["VT"].Token, style = "display:none;" })
        <input type="submit" class="submit_button" /><br />
    }

In the view I am using @Html.HiddenFor(m => m.DummyDictionary) to try to pass the dictionary over to the post method, but the dictionary is just empty. Without this @Html.HiddenFor the Dictionary in the post method is null.

Thank you so much for the assistance I appreciate it!

UPDATE

TheObject

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace DummyMVC.Objects
    {
        public class TheObject
        {
            public string Name { get; set; }
            public string Value { get; set; }
            public string Token { get; set; }
        }
    }
  • 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-10T14:12:02+00:00Added an answer on June 10, 2026 at 2:12 pm

    It’s not pretty but it works. Remember to include all properties of TheObject, if not visible then hidden so they get posted. Would probably be a good idea to make a helper for this.

    @model MvcApplication1.Models.TheModel
    
    @using (Html.BeginForm())
    {
        @Html.LabelFor(m => m.DummyDictionary["VT"].Name)
        @Html.Hidden("DummyDictionary[VT].Name",Model.DummyDictionary["VT"].Name)
        @Html.Hidden("DummyDictionary[VT].Token", Model.DummyDictionary["VT"].Token)
        @Html.TextBox("DummyDictionary[VT].Value", Model.DummyDictionary["VT"].Value)
    
    
        <input type="submit" class="submit_button" /><br />
    }
    

    Controller

        [HttpGet]
        public ActionResult Index()
        {
            TheModel m = new TheModel();
            m.Obj = new TheObject();
            TheObject a_obj = new TheObject();
            a_obj.Name = "Joe";
            m.DummyDictionary = new Dictionary<string, TheObject>();
            m.DummyDictionary.Add("VT", a_obj);
            return View(m);
        }
    
        [HttpPost]
        public ActionResult Index(TheModel model)
        {
            // HERE THE DICTIONARY is EMPTY, where all the form values should exist.
            string test = "";
    
            return View(model);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dictionary cannot have two values with same key. please tell which logic/algorithm being used
Have Dictionary <Int64, byte> that gets used a lot. I mean in a loop
We have the following code in production and it is being used in JSON
I have a simple jQuery ajax method: var sendData = { personId: @(Guid.Empty)}; $.ajax({
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
Does VBA have dictionary structure? Like key<>value array?
I have a Dictionary where the key and value are both strings. It's possible
I have a dictionary, user_dict, and create a list for each user value, this
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have a dictionary with tuples as keys. e.g.: {('tags','1'): 'name', ('name','first'):'rik', ('name','last'):'atee'} In

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.