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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:08:25+00:00 2026-06-15T16:08:25+00:00

View: @model My.Data.Section @using (Html.BeginForm(Save, Sections)) { @Html.Partial(_Fields, Model.Fields); <input type=submit value=Save> } View

  • 0

View:

@model My.Data.Section

@using (Html.BeginForm("Save", "Sections"))
{
    @Html.Partial("_Fields", Model.Fields);

    <input type="submit" value="Save">
}

View JS:

@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
    $(function () {
        $('form').submit(function () {
            if ($(this).valid()) {
                $.ajax({
                    url: this.action,
                    type: this.method,
                    data: $(this).serialize(),
                    success: function (result) {
                        // do some stuff with the returned partial
                    }
                });
            }
            return false;
        });
    });
</script>

Model:

Comes from my data layer (EF5/DBContext/unitofwork)

namespace My.Data
{
    using System;
    using System.Collections.Generic;

    public partial class Section
    {
        public Section()
        {
            this.Fields = new HashSet<Field>();
        }

        public int SectionID { get; set; }
        public int FormID { get; set; }
        public string Name { get; set; }
        public Nullable<int> PrevSection { get; set; }
        public Nullable<int> NextSection { get; set; }
        public int SortOrder { get; set; }

        public virtual ICollection<Field> Fields { get; set; }
        public virtual Form Form { get; set; }
    }
}

Controller:

[HttpPost]
public ActionResult Save(Section model, FormCollection fc)
{
    // do some fun stuff
    return PartialView("_Section", model);
}

When I debug the controller, the model object is not deserialized, I assume this is because I am not using labelfor & textboxfor ect ?

When I inspect the FormCollection object, this has all the keys I need and all the values, however, I’d like to get some other values from my fields, like data-fieldid-itemid=”1″, how would I accomplish this? What’s the best way to do this?

Is it required that I use LabelFor/TextboxFor ?

I guess what I was expecting was the model object to come through with the data filled in, and the sub items of my model object, particularly public virtual ICollection Fields { get; set; } to also be filled in.

I have a feeling I’m missing some concept here, any ideas?

Thanks!

  • 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-15T16:08:26+00:00Added an answer on June 15, 2026 at 4:08 pm

    First, you shouldn’t use Partial views for forms. Instead, you should use EditorTemplates.

    Second, you can’t get attributes because these are not posted to the server by the browser. MVC is stuck with the mechanisms that the browser supports.

    Your options would be, using a submit handler to populate hidden fields with your attributes, put the data in hidden fields to begin with, do an ajax post in which you set all the data you want to post, or simply have your controller “remember” the attributes it set in the GET.

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

Sidebar

Related Questions

I have a view in 2 sections. The top section I input fields and
Question: How do send data to a view model when using command binding? So
I am trying to re-call core-data in UITable using model view. I am in
The INotifyPropertyChanged is obviously very useful in the view model for data binding to
I want to make my data accessible outside of my view model. So I
How can I pass a viewmodel to a view without the model's data showing
What is the Rails way of implementing a view for a data model that
in the django admin, in any app model, the diplay data (datagrid o view
I have a view Index and a Partial View SCItems. I use data annotations
I am trying to update a partial view using ajax, but for some reason

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.