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

The Archive Base Latest Questions

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

I have a custom model binder in my MVC app but I don’t know

  • 0

I have a custom model binder in my MVC app but I don’t know hos I can use T4MVC with it.

Usualy I would Call my action this way :

return RedirectToAction("Edit", "Version", new {contractId = contract.Id.ToString()});

With T4MVC it should be like this :

return RedirectToAction(MVC.Version.Edit(contract));

But since T4 does’nt know about my binder, he try to send the object in the url but what I want is that he generate the url like this : Contract/{contractId}/Version/{action}/{version}

Also note that I have a custom route :

routes.MapRoute(
                "Version", // Route name
                "Contract/{contractId}/Version/{action}/{version}", // URL with parameters
                new { controller = "Version", action = "Create", version = UrlParameter.Optional } // Parameter defaults
            );

This is my binder :

public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var contractId = GetValue(bindingContext, "contractId");
            var version = GetA<int>(bindingContext,"version");

            var contract = _session.Single<Contract>(contractId);
            if (contract == null) 
            {
                throw new HttpException(404, "Not found");
            }
            var user = _authService.LoggedUser();
            if (contract.CreatedBy == null || !contract.CreatedBy.Id.HasValue || contract.CreatedBy.Id.Value != user.Id)
            {
                throw new HttpException(401, "Unauthorized");
            }

            if (contract.Versions.Count < version)
            {
                throw new HttpException(404, "Not found");
            }
            return contract;
        }

What should I do? I don’t want to have magic string in my route…

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-05-21T14:20:54+00:00Added an answer on May 21, 2026 at 2:20 pm

    Try something like this:

    return RedirectToAction(MVC.Version.Edit().AddRouteValues(new {contractId = contract.Id.ToString()}));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my custom model binder. I have my breakpoint set at BindModel but
In my custom model binder I use bindingContext.ValueProvider.GetValue(propertyName); I do have [ValidateInput(false)] on the
I'm using the MVC 2 RC. I have a custom model binder that used
I'm using ASP.NET MVC 3 and have my custom model binder. public class NewsModelBinder
I have written a custom model binder for List in my MVC project however
In my application I have a custom model binder that I set to the
I'm creating a custom model binder in an Mvc application and I want to
I have created a custom Model Binder that inherits from DefaultModelBinder, and overriding the
I have a custom model binder that takes a comma separated list and cleans
I am building an MVC application and am designing a custom model binder for

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.