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

  • Home
  • SEARCH
  • 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 1051013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:51:42+00:00 2026-05-16T16:51:42+00:00

Alright, I’m trying to pass a Dictionary, where key = int, and value =

  • 0

Alright, I’m trying to pass a Dictionary, where key = int, and value = Prototype into my view.

Prototype:

public class Prototype     
{
    public string Value { get; set; }
    public string PropertyName { get; set; }
    public Options Type { get; set; }
}

After the Dictionary has been passed into my view I’m doing a foreach loop to render each of the KeyValuePair:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Dictionary<System.Int32,MvcApplication1.Models.Prototype>>" %>
<%@ Import Namespace="SecuredFormExample.Code" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Index</title>
</head>
<body>
    <div>

    <% Html.BeginForm("Save", "Products", FormMethod.Post); %>

    <% foreach (KeyValuePair<int, Prototype> p in Model)
       { %>
       <%: Html.Label(p.Value.PropertyName) %>
       <%: Html.TextBox("Value") %>
       <% } %>
    <p><input type="submit" value="submit" /></p>

    <% Html.EndForm(); %>

    </div>
</body>
</html>

Now is the question, is it possible to pass the other values in the KeyValuePair value part back to the action aswell, or do I need to throw them all into hidden fields?

  • 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-05-16T16:51:43+00:00Added an answer on May 16, 2026 at 4:51 pm

    If you want to get the values back into the action you are posting to you need to send them along the request. Using hidden fields is one way of doing it. Another way is to only send an identifier which will allow you to fetch those values from a repository in the controller action you are posting to, the same way you are doing it in the controller action which renders the form.

    If you are worried about users tampering with hidden fields you could serialize and encrypt entire objects using the Html.Serialize.


    UPDATE:

    Here’s an example to expand on my second proposition which was to use an id:

    <% Html.BeginForm("Save", "Products", FormMethod.Post) { %>
        <%: Html.Hidden("id", "PUT AN ID HERE WHICH IDENTIFIES THE ITEM")
        <% foreach (KeyValuePair<int, Prototype> p in Model) { %>
           <%: Html.Label(p.Value.PropertyName) %>
           <%: Html.TextBox("Value") %>
        <% } %>
        <p><input type="submit" value="submit" /></p>
    <% } %>
    

    and in your controller action:

    public ActionResult Save(string id, ....) 
    {
        var data = SomeRepository.FetchData(id);
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, I'm trying to read a comma delimited file and then put that into
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright, I know how the fieldset / legend works out in HTML. Say you
Alright, quick question. A server is running in Eastern Time. PHP program needs to
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(

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.