Changing model values when using return CurrentUmbracoPage()
I have the following model:
public class BookingModel{
[UmbracoDisplayName("Booking.DepartureDate")]
public string booking_departure_date { get; set; }
[UmbracoRequired("Booking.Validation.Required")]
[UmbracoRegularExpression("Booking.Validation.Range", "[1-99]")]
[UmbracoDisplayName("Booking.Passengers")]
public int booking_passengers { get; set; }
[UmbracoDisplayName("Booking.FirstName")]
[UmbracoRequired("Booking.Validation.Required")]
public string booking_firstname { get; set; }
[UmbracoDisplayName("Booking.Surname")]
[UmbracoRequired("Booking.Validation.Required")]
public string booking_surname { get; set; }
[UmbracoDisplayName("Booking.Address")]
[UmbracoRequired("Booking.Validation.Required")]
public string booking_address { get; set; }
[UmbracoDisplayName("Booking.PostalCode")]
[UmbracoRequired("Booking.Validation.Required")]
public string booking_postalcode { get; set; }
}
The departure date is populated using a date-picker. However, the user can also type in the text field that is used to select the date. Technically they could enter something stupid like 555555 which is clearly an invalid date.
To try and counteract this I have made the field readonly but the value could still be edited through something like Firebug. I've therefore put the following validation in my controller:
DateTime date = new DateTime();
if (DateTime.TryParseExact(model.booking_departure_date, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
}
else
{
// Could not parse the date meaning it was invalid. Default to todays date
model.booking_departure_date = DateTime.Now.ToString("dd/MM/yyyy");
}
I then check if the modelstate is valid:
if (!ModelState.IsValid || date == new DateTime())
{
/* Clear card details on invalid model */
model.booking_cardnumber = null;
ViewBag.Booking = model;
return CurrentUmbracoPage();
}
However, when the page reloads the value of the textfield is 55555 as if nothing has changed. Why is this and how can I force it to default to the current date in the event that someone tries an invalid entry such as this?
Changing model values when using return CurrentUmbracoPage()
I have the following model:
The departure date is populated using a date-picker. However, the user can also type in the text field that is used to select the date. Technically they could enter something stupid like 555555 which is clearly an invalid date.
To try and counteract this I have made the field readonly but the value could still be edited through something like Firebug. I've therefore put the following validation in my controller:
I then check if the modelstate is valid:
However, when the page reloads the value of the textfield is 55555 as if nothing has changed. Why is this and how can I force it to default to the current date in the event that someone tries an invalid entry such as this?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.