ASP.NET model binding breaks when using decimal values - c#

I have the following scenario. I have a form that post to a controller. Everything works fine when I enter a non decimal number on ValorKilometro input. I can get the model perfectly on the controller and so. The thing is that when I enter a decimal value the ValorKilometro property is always set to 0. Why is that?. Here is the code:
<form name="theForm" action="" style="margin: 0 auto; width: 80%;" method="post" onsubmit="return onFormSubmit();">
...
<div class="form-group">
<label for="usr">Valor de Kilometro:</label>
<input type="number" name="ValorKilometro" min="0" step="any" class="form-control" value="#Model.ValorKilometro">
</div>
<button type="submit" id="boton" class="btn btn-success">Guardar</button>
</form>
Model:
public class ConfiguracionModel
{
public Guid EmpresaGuid { get; set; }
public bool MaximoHabilitado { get; set; }
public int MontoMaximo { get; set; }
public Guid Moneda { get; set; }
public Double ValorKilometro { get; set; }
}
Controller:
[Authorize, AdminAuthorization]
[HttpPost]
public ActionResult Configuracion(ConfiguracionModel configuracion)
{
configuracion.EmpresaGuid = SQL.GetEmpresaGuid(User.Identity.Name);
SQL.ModificarConfiguracion(configuracion);
TempData["msg"] = "<script>alert('Los cambios fueron guardados correctamente!.');</script>";
return View(configuracion);
}
I hope someone can help me out with this.Thanks.

Have you tried using #Html.TextBoxFor helper?
#model ConfiguracionModel // <-- obviously you need to bind your View to your model
#Html.TextBoxFor(m => m.ValorKilometro, "{0:n2}", new {
#class = "form-control",
#type = "number",
#min = "0" })
You can also add the validation constraint to your model:
public class ConfiguracionModel
{
public Guid EmpresaGuid { get; set; }
public bool MaximoHabilitado { get; set; }
public int MontoMaximo { get; set; }
public Guid Moneda { get; set; }
[Range(0.0, double.MaxValue)]
[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
public Double ValorKilometro { get; set; }
}
Note that {0:n2} indicates 2 decimal places.

Related

Post in ASP.net MVC using ASP-for

I'm working on a small library website where you should be able to post a comment to each individual book. The problem is in my view that I can't say "Asp-for='BookComment.Name'" since my BookComment is a list in my Book Model
My Book Model
public class Book
{
[Key]
public int BookID { get; set; }
[Required]
[Column(TypeName = "Varchar(75)")]
public string Title { get; set; }
[Required]
[Column(TypeName = "Varchar(75)")]
public string Author { get; set; }
[Required]
[Column(TypeName = "Varchar(13)")]
public string Isbn { get; set; }
[Required]
[Column(TypeName = "Varchar(50)")]
public string Publisher { get; set; }
public int Sites { get; set; }
public DateTime ReleaseDate { get; set; }
public string Summary { get; set; }
public string Picture { get; set; }
public DateTime AddedDate { get; set; }
public int Stars { get; set; }
public List<BookCategory> BookCategory { get; set; } = new List<BookCategory>();
public List<BookComment> BookComment { get; set; } = new List<BookComment>();
}
BookComment Model:
public class BookComment
{
[Key]
public int BookCommentID { get; set; }
[Required]
public int BookID { get; set; }
[Column(TypeName = "Varchar(50)")]
public string Name { get; set; }
[Column(TypeName = "Varchar(100)")]
public string Email { get; set; }
public string Review { get; set; }
public DateTime Date { get; set; }
public decimal Stars { get; set; }
}
My Book Controller
public class BookController : Controller
{
private readonly ApplicationDbContext _db;
public BookController(ApplicationDbContext db)
{
_db = db;
}
public IActionResult Book(int? id)
{
var book = _db.Books.Include(o => o.BookComment).FirstOrDefault(p => p.BookID == id);
return View(book);
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Book(BookComment comment)
{
_db.bookComments.Add(comment);
_db.SaveChanges();
return RedirectToAction("Book");
}
}
Snippet of my form
#model LibraryNew.Models.Book
<h5 class="mt-4">Tilføj en anmeldelse</h5>
<p>Din email vil ikke blive offentliggjort</p>
<form asp-action="Book" method="post"></form>
<div class="my-3">
<div class="form-group">
<label for="exampleFormControlSelect1">Antal stjerner:</label>
<select class="form-control col-md-1" id="exampleFormControlSelect1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="1">5</option>
</select>
</div>
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Email address</label>
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name#example.com">
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Email address</label>
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name#example.com">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Example textarea</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
I can't say <select asp-for="BookComment.Stars"
Any help is appreciated. If any further information is needed please let me know!
In your view code try replacing #model LibraryNew.Models.Book with #model LibraryNew.Models.BookComment so you can have access to it in asp-for since what you are trying to do is post a single BookComment to add it to a book in your controller.
It looks like what is needed is to be able to use different models in a single page to achieve this you can create a single class that contains the models you will need for a single page for example
public class BookLibrary
{
public Book Book { get; set; }
public BookComment BookComment { get; set; }
public Author Author{ get; set; }
}
then in your view code you use #model LibraryNew.Models.BookLibrary and in your asp-for you will be able to access BookComment by using Model.BookComment

Use interface in ViewModel c# ASP.Net 5

I have some problem.
I have next model:
public class DocumentViewModel
{
public string Nazvanie { get; set; }
public Author DocumentAutors { get; set; }
}
public class Author
{
public long Id { get; set; }
public List<IPerson> Authors { get; set; }
}
public interface IPerson
{
long Id { get; set; }
}
public class PersonUL : IPerson
{
public long Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
public class PersonIP : IPerson
{
public long Id { get; set; }
public string FirstName { get; set; }
public string SecondNAme { get; set; }
public string PostAddress { get; set; }
}
In .cshtml
#model DocumentViewModel
#if (Model.DocumentAutors.Authors != null && Model.DocumentAutors.Authors.Count > 0)
{
for (int i = 0; i < Model.DocumentAutors.Authors.Count; i++)
{
if (Model.DocumentAutors.Authors is PersonUL )
{
<div class="form-group">
<label asp-for="#Model.DocumentAutors.Authors[i].Name" class="col-md-10 control-label"></label>
<div class="col-md-10">
<input asp-for="#Model.DocumentAutors.Authors[i].Name" class="form-control" />
<span asp-validation-for="#Model.DocumentAutors.Authors[i].Name" class="text-danger"></span>
</div>
</div>
}
}
}
Model.DocumentAutors.Authors[i] don't contain "Name" field, because it's interface. I need cast it, but if i write
if (Model.DocumentAutors.Authors is PersonUL )
{
PersonUL ul = (PersonUL)Model.DocumentAutors.Authors[i];
<div class="form-group">
<label asp-for="#ul.Name" class="col-md-10 control-label"></label>
<div class="col-md-10">
<input asp-for="#ul.Name" class="form-control" />
<span asp-validation-for="#ul.Name" class="text-danger"></span>
</div>
</div>
}
i will get html with wrong name like this
<input class="form-control" type="text" id="Name" name="Name" value="566">
instead
<input class="form-control" type="text" id="DocumentAutors.Authors[0].Name" name="DocumentAutors.Authors[0].Name" value="566">
and ModelBinder will not bint this field into Authors List.
Is there a solution for this problem or should I make one generic model for PersonUL and PersonIP with all fields, which I don't really like it?
I am sorry but IMHO I don't see any advantages in the interface. It only makes the code more confused.
Why you don't try
public class Author
{
public long Id { get; set; }
public List<PersonIP> IpAuthors { get; set; }
public List<PersonUL> UlAuthors { get; set; }
}
or even better
public class DocumentViewModel
{
public string Nazvanie { get; set; }
public long AuthorId { get; set; }
public List<PersonIP> IpAuthors { get; set; }
public List<PersonUL> UlAuthors { get; set; }
}

The property is of an interface type ('IFormFile') MVC Core

I'm trying to make a form that i could save a file(image) , but it shows me an error:
InvalidOperationException: The property 'Product.Image' is of an interface type ('IFormFile'). If it is a navigation property manually configure the relationship for this property by casting it to a mapped entity type, otherwise ignore the property from the model.
Apply
I dont know how to fix it , here's the code:
Product.cs
public class Product
{
public Product()
{
OrderDetails = new HashSet<OrderDetails>();
}
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int? CategoryId { get; set; }
public decimal? Price { get; set; }
public int? Quantity { get; set; }
public string ImagePath { get; set; }
public virtual ICollection<OrderDetails> OrderDetails { get; set; }
public virtual Category Category { get; set; }
}
ProductFormViewModel.cs
public class ProductFormViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int? CategoryId { get; set; }
public decimal? Price { get; set; }
public int? Quantity { get; set; }
public IFormFile Image { get; set; }
}
Create Action
[HttpGet]
public IActionResult Create()
{
var categories = _repository.GetCategories().ToList();
var categoriesModel = categories.Select(p => new
{
p.Id,
p.Name
});
ViewBag.Categories = new SelectList(categoriesModel, "Id", "Name");
return View();
}
[HttpPost]
public IActionResult Create(ProductFormViewModel product)
{
var file = product.Image; // **it returns NULL**
var upload = Path.Combine(_environment.ContentRootPath, "wwwroot\\uploads", product.Name);
if (!Directory.Exists(upload))
Directory.CreateDirectory(upload);
var filePath = Path.Combine(upload, file.FileName);
if (file.Length > 0)
{
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
file.CopyTo(fileStream);
}
}
var producti = new Product();
producti.CategoryId = product.CategoryId;
producti.Description = product.Description;
producti.Name = product.Name;
producti.Price = product.Price;
producti.Quantity = product.Quantity;
producti.ImagePath = filePath;
_repository.AddProduct(producti);
_repository.SaveChanges();
return RedirectToAction("Index","Products");
}
Create.cshtml
#model ProductFormViewModel
<br />
<br />
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
</div>
<div class="panel-body">
<form class="form-group" asp-action="Create" asp-controller="Products" method="post">
<input type="hidden" asp-for="Id"/>
<div class="col-md-12">
<div class="form-group col-md-6">
<label asp-for="Name" class="control-label col-md-3"></label>
<input asp-for="Name" type="text" class="form-control col-md-3"/>
</div>
<div class="form-group col-md-6">
<label asp-for="CategoryId" class="control-label col-md-3"></label>
<select asp-for="CategoryId" asp-items="#ViewBag.Categories" class="form-control col-md-3">
<option hidden disabled selected >Select One</option>
</select>
</div>
<div class="form-group col-md-6">
<label asp-for="Description" class="control-label col-md-3"></label>
<textarea asp-for="Description" class="form-control" rows="4"></textarea>
</div>
<div class="form-group col-md-6">
<label asp-for="Price" class="control-label col-md-3"></label>
<input type="text" asp-for="Price" class="form-control col-md-3"/>
</div>
<div class="form-group col-md-6">
<label asp-for="Quantity" class="control-label col-md-3"></label>
<input type="text" asp-for="Quantity" class="form-control col-md-3"/>
</div>
<div class="form-group col-md-12">
<label class="control-label">Select Image</label>
<input asp-for="Image" type="file" class="btn-file"/>
</div>
<div class="form-group col-md-12 text-center">
<input type="submit" class="btn btn-success" value="Save"/>
</div>
</div>
</form>
</div>
</div>
</div>
IFormFile is a type used by the ASP.NET Core framework and it does not have a sql server type equivalent.
For your domain model store it as byte[] and when you work with views, is ok for you to use the IFormFile type.
ProductModel:
public class Product
{
public Product()
{
OrderDetails = new HashSet<OrderDetails>();
}
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int? CategoryId { get; set; }
public decimal? Price { get; set; }
public int? Quantity { get; set; }
public string ImagePath { get; set; }
public virtual ICollection<OrderDetails> OrderDetails { get; set; }
public virtual Category Category { get; set; }
}
ProductViewModel:
public class ProductViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int? CategoryId { get; set; }
public decimal? Price { get; set; }
public int? Quantity { get; set; }
public IFormFile Image { get; set; }
}
Controller method:
[HttpGet]
public IActionResult Create()
{
var categories = _repository.GetCategories().ToList();
var categoriesModel = categories.Select(p => new
{
p.Id,
p.Name
});
ViewBag.Categories = new SelectList(categoriesModel, "Id", "Name");
return View();
}
[HttpPost]
public IActionResult Create(ProductViewModel model)
{
// Save the image to desired location and retrieve the path
// string ImagePath = ...
// Add to db
_repository.Add(new Product
{
Id = model.Id,
ImagePath = ImagePath,
// and so on
});
return View();
}
Also specify to the form enctype="multipart/form-data" in your view.
using System.ComponentModel.DataAnnotations.Schema;
namespace model{
public class ProductViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int? CategoryId { get; set; }
public decimal? Price { get; set; }
public int? Quantity { get; set; }
[NotMapped]
public IFormFile Image { get; set; }
}
}

Asp.net MVC C# One Form, Two Model

I have two models like below.
public class Bill
{
public int Id { get; set; }
public string InvoiceNumber { get; set; }
public Int64 Amount { get; set; }
public int? NewPaymentId { get; set; }
public virtual NewPayment RelPayment { get; set; }
}
public class NewPayment
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LstName { get; set; }
public DateTime PaymentDate { get; set; }
public Int64 ProvisionNumber { get; set; }
public Int64 CreditCardNumber { get; set; }
public int ExpMonth { get; set; }
public int ExpYear { get; set; }
public int Cv2 { get; set; }
public Int64 Amount { get; set; }
public string UserId { get; set; }
public string CustomerNote { get; set; }
}
Customer is going to pay his invoices via credit card in my application.
I had one view which i posted the NewPayment model to the action. But now, i need to send also which invoices will be paid. So i need to create one more form for the Bill model i think ? But i cant figure out how can i pass two model to same action and i dont know the NewPaymentId before executing the payment method.
REGARDING TO THE COMMENTS :
My combine model as below :
public class Payment
{
public IEnumerable<Bill> Bill { get; set; }
public NewPayment NewPayment { get; set; }
}
And my view as below :
#model IEnumerable<ModulericaV1.Models.Bill>
<form class="form-no-horizontal-spacing" id="NewPayment" action="/NewPayment/AddInvoice" method="post">
<div class="row column-seperation">
<div class="col-md-6">
<h4>Kart Bilgileri</h4>
<div class="row form-row">
<div class="col-md-5">
<input name="FirstName" id="FirstName" type="text" class="form-control" placeholder="Kart Üzerindeki Ad">
</div>
<div class="col-md-7">
<input name="LastName" id="LastName" type="text" class="form-control" placeholder="Kart Üzerindeki Soyad">
</div>
</div>
<div class="row form-row">
<div class="col-md-12">
<input name="CreditCardNumber" id="CreditCardNumber" type="text" class="form-control" placeholder="Kart Numarası">
</div>
</div>
<div class="row form-row">
<div class="col-md-5">
<input name="ExpYear" id="ExpYear" type="text" class="form-control" placeholder="Son Kullanma Yıl (20..)">
</div>
<div class="col-md-7">
<input name="ExpMonth" id="ExpMonth" type="text" class="form-control" placeholder="Son Kullanma Ay (1-12)">
</div>
</div>
<div class="row form-row">
<div class="col-md-5">
<input name="Cv2" id="Cv2" type="text" class="form-control" placeholder="Cv2">
</div>
<div class="col-md-7">
<input name="Amount" id="Amount" type="text" class="form-control" placeholder="Miktar TL ">
</div>
</div>
<div id="container">
<input id="Interests_0__Id" type="hidden" value="" class="iHidden" name="Interests[0].Id"><input type="text" id="InvoiceNumber_0__InvoiceNumber" name="[0].InvoiceNumber"><input type="text" id="Interests_0__InterestText" name="[0].Amount"> <br><input id="Interests_1__Id" type="hidden" value="" class="iHidden" name="Interests[1].Id"><input type="text" id="InvoiceNumber_1__InvoiceNumber" name="[1].InvoiceNumber"><input type="text" id="Interests_1__InterestText" name="[1].Amount"> <br>
</div>
<input type="button" id="btnAdd" value="Add New Item" />
<button class="btn btn-danger btn-cons" type="submit"> Ödemeyi Gerçekleştir</button>
</form>
</div>
</div>
In my controller, i am getting payment model as null.
public ActionResult AddInvoice(Payment payment) {
foreach (var item in payment.Bill)
{
var Billing = new Bill();
Billing.Amount = item.Amount;
Billing.InvoiceNumber = item.InvoiceNumber;
db.Bill.Add(Billing);
db.SaveChanges();
}
return View();
}
}
i complete Marko with an example
public class CombineModel
{
public Bill Bill{ get; set; }
public NewPayment NewPayment{ get; set; }
}
You appear to already have the solution in your model. Your bill object can hold a reference to a related new payment. You can either lazy read the new payment from database or you could assign a new newpayment object to the bill before sending to the view.
View models are good practice, but you might be happy levering the model you have naturally as I just described.
Update
Sorry, this should be:
The other way around - Pass in NewPayment
Add public IEnumarable<Bill> Bills {get; set;} to NewPayment model
And that way, you can access the Bills associated with the given payment.
Code first stuff:
You should decorate Bill's RelPayment with [ForeignKey("NewPaymentID"], so EF (I assume you are using Entity Framework), knows how to wire up the relationship.
You will also likely need to add the following Bills = new List<Bill>(); into a NewPayment constructor.
If you don't like Zakos Solution you can make tuple :
var tuple= new Tuple<Bill,NewPayment>(obj1,obj2);
And in view you will have :
#model Tuple<Bill,NewPayment>
But you should use #Zakos solution.
So you can use ViewModel, take this ViewModel:
public class PaymentBillViewModel
{
public int BillId { get; set; }
public int PaymentId { get; set; }
public string InvoiceNumber { get; set; }
public Int64 Amount { get; set; }
public int? NewPaymentId { get; set; }
public virtual NewPayment RelPayment { get; set; }
public int Id { get; set; }
public string FirstName { get; set; }
public string LstName { get; set; }
public DateTime PaymentDate { get; set; }
public Int64 ProvisionNumber { get; set; }
public Int64 CreditCardNumber { get; set; }
public int ExpMonth { get; set; }
public int ExpYear { get; set; }
public int Cv2 { get; set; }
public Int64 Amount { get; set; }
public string UserId { get; set; }
public string CustomerNote { get; set; }
}
actually put what you need in your View. then in the post action cast the ViewModel to the related Model:
[HttpPost]
public ActionResult Sample(PaymentBillViewModel model)
{
if (ModelState.IsValid)
{
var obj=new NewPayment
{
LstName= model.LstName,
Amount=model.Amount,
//... cast what else you need
}
}
return View();
}
you can use Automapper on casting, for more info about using Automapper take a look at this article.

Entity Framework 4.1 - Code First - Cannot update nullabe DateTime values while resolving DbUpdateConcurrencyException

I currently have an entity that I'm trying to edit through my MVC 3 web app. I receive an DbUpdateConcurrencyExceptionwhen trying to perform a the client wins approach I got from MSDN's post Using DbContext in EF 4.1 Part 9: Optimistic Concurrency Patterns. The weird part is that this only happens on this particular entity and there I'm not doing anything different from the other. Also, it only happens when updating from a null to a value. The Properties giving the error when updating from null value to a DateTime value are DispositionLetterDate and DateDisposition.
Class:
public class A22
{
public A22()
{
this.IsArchived = false;
this.A22StatusId = (int)AStatus.Open;
}
[Key]
public int Id { get; set; }
[Required]
[StringLength(100, ErrorMessage="A22 Number cannot exceed 100 characters")]
public string Number { get; set; }
[Display(Name="Manual")]
public int ManualId { get; set; }
[Display(Name="SGMLID")]
public string SGMLId { get; set; }
[Required]
[DataType(DataType.Date)]
[Display(Name="Date Received")]
public DateTime DateReceived { get; set; }
[Display(Name= "Status")]
[EnumDataType(typeof(A22Status))]
public int A22StatusId { get; set; }
[Display(Name="Priority")]
[EnumDataType(typeof(A22Priority))]
public int A22PriorityId { get; set; }
[Display(Name="Providing Disposition")]
public string ProvidingDisposition { get; set; }
[Display(Name="Final Disposition")]
public bool FinalDisposition { get; set; }
[Display(Name="Is Archived")]
public bool IsArchived { get; set; }
[Display(Name="Created By")]
public int CreatedById { get; set; }
[Display(Name="Date Created")]
public DateTime DateCreated { get; set; }
[ConcurrencyCheck]
[Display(Name="Date Modified")]
public DateTime DateModified { get; set; }
[Display(Name = "Disposition Date")]
public DateTime? DateDisposition { get; set; }
[Display(Name = "Date Disposition Letter Sent")]
public DateTime? DispositionLetterDate{ get; set; }
// Virtual Properties
[ForeignKey("CreatedById")]
public virtual User CreatedBy { get; set; }
[ForeignKey("ManualId")]
public virtual Manual Manual { get; set; }
public virtual ICollection<A22Manual> A22ManualsImpacted { get; set; }
public virtual ICollection<A22Task> A22TasksImpacted { get; set; }
public virtual ICollection<A22Comment> Comments { get; set; }
public virtual ICollection<A22HistoryLog> HistoryLogs { get; set; }
}
Controller:
[HttpPost]
public ActionResult Edit(A22 a22)
{
var d = new A22Repository().Find(a22.Id);
var changes = TrackChanges(d, a22);
if (ModelState.IsValid) {
if (!string.IsNullOrEmpty(changes))
{
repository.InsertOrUpdate(a22);
this.repository.AddHistory(a22, changes);
repository.Save();
}
return RedirectToAction("Details", new { id = a22.Id });
} else {
ViewBag.PossibleManuals = d.ManualId == default(int) ? manualRepo.GetManualList() :
manualRepo.GetManualList(d.ManualId);
ViewBag.APriority = repository.GetAPriorityList(d.APriorityId);
ViewBag.AStatus = repository.GetAStatusList(d.APriorityId);
return View();
}
}
}
View:
#model TPMVC.Web.Models.A22
#{
Layout = "~/Views/Shared/_BlendLayoutLeftOnly.cshtml";
ViewBag.Title = "Edit";
}
<h2>Edit A22# #Model.Number</h2>
#using (Html.BeginForm())
{
#Html.ValidationSummary(true)
#Html.HiddenFor(model => model.Id)
#Html.HiddenFor(model => model.CreatedById)
#Html.HiddenFor(model => model.DateCreated)
#Html.HiddenFor(model => model.DateModified)
#Html.Partial("_CreateOrEdit")
<div class="newItemLabel">
<strong style="padding-right: 145px;">#Html.LabelFor(model => model.AStatusId)</strong>
#{
Html.Telerik().DropDownList()
.Name("AStatusId")
.BindTo((IEnumerable<SelectListItem>)ViewBag.AStatus)
.HtmlAttributes(new { #style = "width: 200px;" })
.Render();
}
#Html.ValidationMessageFor(model => model.AStatusId)
</div>
<div class="newItemLabel">
<strong style="padding-right: 77px;">#Html.LabelFor(model => model.FinalDisposition)</strong>
#Html.EditorFor(model => model.FinalDisposition)
</div>
<div class="newItemLabel">
<strong style="padding-right: 44px;">#Html.LabelFor(model => model.DateDisposition)</strong>
#{
Html.Telerik().DatePickerFor(model => model.DateDisposition)
.Render();
}
</div>
<div class="newItemLabel">
<strong style="padding-right: 44px;">#Html.LabelFor(model => model.DispositionLetterDate)</strong>
#{
Html.Telerik().DatePickerFor(model => model.DispositionLetterDate)
.Render();
}
</div>
<div class="newItemLabel">
<strong style="padding-right: 110px;">#Html.LabelFor(model => model.IsArchived) </strong>
#Html.EditorFor(model => model.IsArchived)
</div>
<p>
<input type="submit" value="Save" />
</p>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
Thinking it was could have been something with the data annotations, I decided to define the properties with this issue to optional using the Fluid API.
modelBuilder.Entity<A22>().Property(a => a.DateDisposition).IsOptional();
modelBuilder.Entity<A22>().Property(a => a.DispositionLetterDate).IsOptional();
I basically need a fresh pair of eyes to see if I'm missing something. Is there other property that is making it behave this way?
Thanks in advance.
I'm mapping nullable DateTime properties like following without IsOptional methods. Also it works fine with MS SQL and MySQL by me.
this.Property(t => t.CreatedDate).HasColumnName("CreatedDate");
this.Property(t => t.ModifiedDate).HasColumnName("ModifiedDate");
in class derived from EntityTypeConfiguration. I'm using Code First approach.

Categories

Resources