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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:20:21+00:00 2026-05-25T17:20:21+00:00

I am building an ajax form using the MVC Ajax Helpers: http://msdn.microsoft.com/en-us/library/dd505013.aspx The code

  • 0

I am building an ajax form using the MVC Ajax Helpers: http://msdn.microsoft.com/en-us/library/dd505013.aspx

The code looks similar to:

Ajax.BeginForm("ActionName", "ControllerName",
    new {
            SomeProperty = (ViewData["SomeObject"] as SomeClass).SomeProperty,
            AnotherProperty = (ViewData["SomeObject"] as SomeClass).AnotherProperty,
            AllTheProperties = (ViewData["SomeObject"] as SomeClass).AllTheProperties,
            otherProperty= ViewData["otherObject"]
        },
  new AjaxOptions {},
  new {id = "anHtmlId"} );

but there are plenty of more properties in ViewData["SomeObject"] though.

I would like to add ViewData["otherObject"] to the routeData object simply with as few lines as possible and do not want have all of the properties of someObject laid out individually so that I can add properties to it without having to revisit this code in the view.

Essentially “merging” these objects to pass as the routeData parameter would be useful.


Update: an idea:

Ajax.BeginForm("ActionName", "ControllerName",
    ViewData["SomeObject"].addThePropertiesOf(ViewData["otherObject"]),
  new AjaxOptions {},
  new {id = "anHtmlId"} );

Where addThePropertiesOf() returns a new merged object. I wouldn’t like to use the expensive bits of reflection otherwise this doesn’t seem performant.

  • 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-25T17:20:22+00:00Added an answer on May 25, 2026 at 5:20 pm

    What’s the point of sending some values to the HTML which cannot be modified by the user as they are not part of the form as input elements just to resend them back on postback as query string parameters? Makes no sense. It’s a total waste of bandwidth. For me all you need to send to the server when you post this form is some unique identifier (in addition of course to all the form fields that the user can modify):

    Ajax.BeginForm(
        "ActionName", 
        "ControllerName", 
        new { id = (ViewData["SomeObject"] as SomeClass).Id }, 
        new AjaxOptions { }, 
        new { id = "anHtmlId"} 
    )
    {
        ... some input fields that the user can modify and
            that will automatically be sent to the server when
            the form is submitted
    }
    

    And of course for all values that can be modified you will have corresponding input fields whose values would obviously be automatically posted to the server.

    Finally on the server use this unique identifier to refetch the original values from wherever you fetched them in your GET action when you rendered the form. You fetched them from somewhere, right, otherwise you wouldn’t have been able to store them in the ViewData in the first place.

    And please get rid of those ViewData/ViewBag, define view models and use strongly typed views. I am starting to exhibit some real allergies towards those two weakly typed constructs that should never be used in any ASP.NET MVC application.

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

Sidebar

Related Questions

I've successfully installed this jQuery-based signup form here: http://net.tutsplus.com/tutorials/javascript-ajax/building-a-sleek-ajax-signup-form/ But when I applied it
I am building a AJAX intensive web application (using ASP.NET, JQuery, and WCF web
I'm building an application which uses ajax calls for form validations and some others,
I am building an order form using HTML and jQuery and it is complete,
I am building a chat application using JSP, Servlets and Ajax with Smack API.
I am building out an ajax enabled UI using webforms in asp.net. I really
I'm building my first AJAX website where I implemented a custom MVC. Basicly I'm
I am building a small ajax contact form and i am testing it with
How can i code for country state dropdowns in zend framework using ajax I
We're building a web app, and it's using jquery ajax and jsp on the

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.