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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:33:33+00:00 2026-06-06T10:33:33+00:00

I am starting to switch over my Controllers to use model binders for GET

  • 0

I am starting to switch over my Controllers to use model binders for GET actions instead of using an int parameter. My normal controller GET action looks like the following …

public ActionResult Details(int id)
{
    DomainModel model = repository.GetById(id);
    if (model == null)
    {
        throw new HttpException(404, "Item does not exist")
    }

    //Continue along with our controller action
}

When switch to a ModelBinder I wanted to throw the HttpException in the BindModel method, however I am unsure if it is considered a good programming practice. Is the controller responsiblity for throwing the 404 or the ModelBinder?

  • 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-06T10:33:36+00:00Added an answer on June 6, 2026 at 10:33 am

    Model binding does just that, binds the model. if the model doesn’t exist it would return either null or a Null Object. The controller could then decide what to do with the model. If it’s null, throw.

    however if you you see the same lines of code appearing than it’s a good idea to encapsulate that code. One option would be to use an ActionFilter. the model binder creates the objects and the action filter can set the response code to 404 if the model is null.

    in this scenario your controller only needs to worry about the “happy path”. That is the model exists.

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

Sidebar

Related Questions

Starting in SQL 2005, VARCHAR(MAX) is no longer limited to 8000 bytes, it instead
Starting with no cache on server or client FIRST REQUEST GET /post/1 HTTP/1.1 HTTP/1.1
Starting from Visual Studio 2010, iterating over a set seems to return an iterator
Starting a new project using EJB 3 / JPA, mainly stateless session beans and
I can't believe this - I just starting developing an SSRS report, using a
I'm interested in starting up my computer before I get to work because we
I'm currently starting to use a responsive approach to my sites. I've found http://fluidbaselinegrid.com/
I recently had to switch from using Microsofts SQL server to using MySQL. The
My web app offers personalized recommendations. When a user starting to use it, about
After attempting to switch my Rails app to thin server using these instructions ,

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.