[]
There is not a runtime error, only it occurs on the page itself. When I try to enter a decimal price on input field, there is a warning on the page.
View:
<div class="form-group row">
<div class="col-4">
</div>
<div class="col-8">
@if (product != null)
{
<button type="submit" class="btn btn-danger form-control" asp-action="Remove" asp-route-id="@Model.Id">
Remove to Cart
</button>
}
else
{
<input type="submit" class="btn btn-info form-control" value="Add to Cart" />
}
</div>
</div>
</div>
Controller:
public ActionResult Detail(int? id)
{
if (id == null)
{
return NotFound();
}
var product=_db.Products.Include(c=>c.ProductTypes).FirstOrDefault(c=>c.Id == id);
{
if (product == null)
{
return NotFound();
}
}
return View(product);
}
Model:
public class Product
{
public int Id { get; set; }
[Required]
public string? Name { get; set; }
[Required]
public decimal? Price { get; set; }
public string? Image { get; set; }
[Display(Name ="Product Color")]
public string? ProductColor { get; set; }
[Required]
[Display(Name ="Available")]
public bool IsAvailable { get; set; }
[Display(Name ="Product Type")]
[Required]
public int ProductTypeId { get; set; }
[ForeignKey("ProductTypeId")]
public ProductTypes? ProductTypes { get; set; }
}
I thought to delete the nullable sign of price “decimal” in models, but it will change all of the order in migration. What are the possible other solutions for that?