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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:16:57+00:00 2026-05-28T05:16:57+00:00

Ok, this is weird. I cannot use BindAttribute ‘s Include and Exclude properties with

  • 0

Ok, this is weird. I cannot use BindAttribute‘s Include and Exclude properties with complex type nested objects on ASP.NET MVC.

Here is what I did:

Model:

public class FooViewModel {

    public Enquiry Enquiry { get; set; }
}

public class Enquiry {

    public int EnquiryId { get; set; }
    public string Latitude { get; set; }
}

HTTP POST action:

[ActionName("Foo"), HttpPost]
public ActionResult Foo_post(
    [Bind(Include = "Enquiry.EnquiryId")]
    FooViewModel foo) {

    return View(foo);
}

View:

@using (Html.BeginForm()) {

    @Html.TextBoxFor(m => m.Enquiry.EnquiryId)
    @Html.TextBoxFor(m => m.Enquiry.Latitude)

    <input type="submit" value="push" />
}

Does not work at all. Can I only make this work if I define the BindAttribute for Enquiry class as it is stated here:

How do I use the [Bind(Include="")] attribute on complex nested objects?

  • 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-28T05:16:58+00:00Added an answer on May 28, 2026 at 5:16 am

    Yes, you can make it work like that:

    [Bind(Include = "EnquiryId")]
    public class Enquiry 
    {
        public int EnquiryId { get; set; }
        public string Latitude { get; set; }
    }
    

    and your action:

    [ActionName("Foo"), HttpPost]
    public ActionResult Foo_post(FooViewModel foo) 
    {
        return View(foo);
    }
    

    This will include only the EnquiryId in the binding and leave the Latitude null.

    This being said, using the Bind attribute is not something that I would recommend you. My recommendation is to use view models. Inside those view models you include only the properties that make sense for this particular view.

    So simply readapt your view models:

    public class FooViewModel 
    {
        public EnquiryViewModel Enquiry { get; set; }
    }
    
    public class EnquiryViewModel 
    {
        public int EnquiryId { get; set; }
    }
    

    There you go. No longer need to worry about binding.

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

Sidebar

Related Questions

This is really weird, and I cannot see why this is happening. In the
In IntelliJ I get this weird error when I try to compile. Cannot find
I have pretty weird question. In my ASP.NET MVC application I defined 1 Timer
This error is weird and i cannot make much sense of it. I've installed
This is very weird. Apparently, I can use both .val() and .text() to manipulate
I've seen this weird behavior on several sites recently: I scroll down a page
I've got this weird problem - I'm calling ChangeServiceConfig on a newly installed service
I'm experiencing this weird problem which my scrollbar jumps by itself to somewhere that
I got this weird error which mentions I should install VSTS 2008 SP1, during
I got this weird error when I wanted to validate my in-memory xml Schema,

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.