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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:38:20+00:00 2026-05-14T01:38:20+00:00

I am using ASP.NET MVC 2, and am using a view-model per view approach.

  • 0

I am using ASP.NET MVC 2, and am using a view-model per view approach. I am also using Automapper to map properties from my domain-model to the view-model.

Take this example view-model (with Required data annotation attributes for validation purposes):

public class BlogPost_ViewModel
{
    public int Id { get; set; }
    [Required]
    public string Title { get; set; }
    [Required]
    public string Text { get; set; }
}

In the post editor view I am using a rich text editor (CKeditor). Because CKeditor is a HTML editor, I ideally need CKeditor to HTMLencode the user’s input when the form is submitted, so that ASP.NET’s input validation does not complain. This is not a problem as CKeditor has this functionality built in, however I need CKeditor’s output decoded before mapping back to the domain object (via Automapper).

I am wanting to add a new property (to the view-model above) to solve this, as follows:

public string HTMLEncodedText {
    get { return HTMLEncode(Text); }
    set { Text = HTMLDecode(value); }
}

I can then bind this property to CKeditor in the view, but still use Automapper to map the ‘Text’ property in the controller – all without having to turn input-validation off.

My question is: do you know how the model binding and validation process in ASP.NET MVC 2 works? Are all model properties binded before validation is carried out? Or is each individual property get validated when it is being set. I think ideally for my idea to work, all properties need to be set before the model is validated.

  • 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-14T01:38:20+00:00Added an answer on May 14, 2026 at 1:38 am

    The properties are validated first then they are bound. So for your view model, you might have to set [Required] on your HTMLEncodedText property instead of on your Text property.

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

Sidebar

Related Questions

I'm using AutoMapper to map domain entities to view models in an Asp.Net MVC
I'm using ASP.NET MVC 2 and here's the issue. My View Model looks something
I am creating an application using asp.net MVC. By default, the model, view and
I am using Asp.net MVC 3 and Json.net library. I have view model class
The service layer of my ASP.NET MVC 3 application uses AutoMapper to map view
I'm using ASP.NET MVC 3 and the helper @Html.Raw in my view. I'm passing
I'm using some javascript/jquery in an asp.net mvc view and I'm appending some html
Possible Duplicate: Client Id for Property (ASP.Net MVC) In my View I'm using jquery
I'm using the spark view engine with my asp.net mvc application. In my aspx
I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,

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.