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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:03:48+00:00 2026-05-27T20:03:48+00:00

I have this action in my RESTful application on MVC3: [HttpPut] public void Rest(ViewModel

  • 0

I have this action in my RESTful application on MVC3:

[HttpPut]
public void Rest(ViewModel view_model, int id)
{
    //doing something with view_model
}

Where ViewModel class is a class for passing data to/from client Javascript (I don`t want to pass pure DB entities):

public class ViewModel
{
    public ViewModel()  //parameterless constructor, needed for accepting as parameter in action
    {
    }

    public ViewModel(Model m)
    {
        id = m.ID;
        Title = m.Title;
    }

    public int? id { get; set; }

    private string _title;
    public string Title
    {
        get
        {
            if (String.IsNullOrWhiteSpace(_title)) throw new Exception("Empty field");
            return _title;
        }
        set
        {
            _title = value;
        }
    }
}

BUT when I make PUT request with that data:

{ "id" :    7, "Title" : "Hello world!" }

I get that “Empty field” exception. Seems like something is trying to get Title property, even before it has been set with incoming “Hello world!” data.
Why?

And where can I get some information, how this whole operation works, i.e. looking for object ViewModel that specified as action parameter, in actual XHR-request.

Thank you for your thoughts.

  • 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-27T20:03:49+00:00Added an answer on May 27, 2026 at 8:03 pm

    Seems like something is trying to get Title property, even before it
    has been set with incoming “Hello world!” data. Why?

    It is the default model binder. And more specifically the BindProperty method. This method is called during binding and it uses reflection to call the getter. Because the model binder recurses down the object hierarchy graph it first needs to get the value of the property, build a binding context and model metadata for each property and then invoke the SetProperty method.

    If you don’t want the title property to be empty use the validation mechanisms and auto implemented properties:

    [Required]
    public string Title { get; set; }
    

    and then in your RESTful action check if the ModelState.IsValid. It is much more easier and MVCish:

    [HttpPut]
    public ActionResult Rest(ViewModel view_model, int id)
    {
        if (!ModelState.IsValid)
        {
            ...
        }
    
        // doing something with view_model
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
I have this route: {controller}/{id}/{action} Because I think it makes more sense from RESTful
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
I have to do through Action like this: Action action = () => {
I have an URL like this /home/action/id How can I access this id in
EDIT: See this in action here: http://jsbin.com/emobi/5 -- and that's using mouseenter/mouseleave. I have
I'm sure I have seen this syntax <%= Url.Action((MyController c) => c.MyMethod(a)) %> or
I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
i have form action file in another directory but some file send to this

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.