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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:41:13+00:00 2026-05-30T11:41:13+00:00

I have a simple model for a contract: public class Contract { public int

  • 0

I have a simple model for a contract:

public class Contract
{
    public int Number { get; set; }
    public DateTime DateSigned { get; set; }
}

When creating a new contract I’d like to automatically suggest the next available number. I get it from the database in my controller’s Create action.

public Create()
{
    ViewBag.SuggestNum = /* ... */;
    return View();
}

In my View I have an EditorFor my Number and my DateSigned:

@Html.EditorFor( m => m.DateSigned )
@Html.EditorFor( m => m.Number )

I’ve tried both of these but they seem to have no effect whatsoever on the resulting html:

@Html.EditorFor( m => m.Number, new { @value = ViewBag.SuggestNum.ToString() } ) 
@Html.EditorFor( m => m.Number, new { @Value = ViewBag.SuggestNum.ToString() } )

Another option is to construct a Contract object in my controller but then my non-nullable DateTime property’s editor defaults to 01.01.0001 instead of being empty:

public Create()
{
    var SuggestNum = /* ... */;

    // The new object has a DateSigned property with the default value of 01.01.0001
    return View( new Contract() { Number = SuggestNum }); 
}

So this doesn’t work either.

Any ideas how to set the value of my Number property’s editor but not my DateSigned’s?

  • 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-30T11:41:15+00:00Added an answer on May 30, 2026 at 11:41 am

    You could make the DateSigned property a Nullable<DateTime>:

    public class Contract
    {
        public int Number { get; set; }
    
        [Required]
        public DateTime? DateSigned { get; set; }
    }
    

    and then in your controller:

    public ActionResult Create()
    {
        var suggestNum = ... fetch from db
        return View( new Contract() { Number = suggestNum }); 
    }
    

    and in your view:

    @Html.EditorFor( m => m.DateSigned )
    @Html.EditorFor( m => m.Number )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple model public class OneModel { public string Email { get;
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a Rails 3 simple scaffolded application having one model like that: class
I have a simple model class (Part), which pulls from it's information from a
I'm relatively new to the Component Object Model specification - I have a simple
I have 2 simple models; a JobInfo model and a Contact model. class JobInfo(models.Model):
We have a simple domain model: Contact, TelephoneNumber and ContactRepository. Contact is entity, it
I have a simple model called Party with a corresponding table called parties .
I have a simple data model of two tables, email and recipients, email can
I have a simple Poco-Model using abstract classes, and it seems not to work

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.