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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:58:58+00:00 2026-06-13T19:58:58+00:00

I have a property which is set to required via data annotation. This works

  • 0

I have a property which is set to required via data annotation. This works perfectly fine for the create form but I would like to make the property not required in the edit form. How can I go about doing that?

  • 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-13T19:58:59+00:00Added an answer on June 13, 2026 at 7:58 pm

    You can create seperate view models for create and edit views. You can keep the common properties in a common class and inherit those 2 view models from that common class.

    public class CustomerViewModel
    {      
      public string Name { set;get;}      
      public string Location { set;get;}      
    }
    public class CreateCustomer :CustomerViewModel
    {
      [Required]
      public string LastJobTitle { set;get;}
    }
    public class EditCustomer :CustomerViewModel
    {  
      public string LastJobTitle { set;get;}
    }
    

    And you can use these in your Action method like this

    public ActionResult Create()
    {
      var createVM=new CreateCustomer();
      return View(createVM);
    }
    public ActionResult Edit(int id)
    {
      var editVM=new EditCustomer();
      var customerModel=repositary.GetCustomer(id);
      editVM.LastJobTitle=customerModel.LastJobTitle;
      //set other properties also
      return View(createVM);
    }
    

    So your create view will be strongly typed to CreateCustomer class and edit view will be strongly typed to EditCustomer class.

    Create.cshtml

    @model CreateCustomer
    

    Edit.cshtml

    @model EditCustomer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an access table I have a column which has the Required property set
I have a class called Property which has nothing but get -methods. All the
I have written a attached property which stores amongst others a help text. This
I have a Model property which the controller sets to 1 but in my
Hi I have a property in one of my models which is: [Required(ErrorMessage =
I have a Silverlight control which maintains a set of children. This set of
I have a Backbone View which handles a registration component, because this required a
I have a few classes which have a property which is unique to that
I have a hidden property which is fetched from ebean. how do i pass
I have a property column which can have a subset of the following values

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.