I have 2 models in this form The main model is Beverage
[Serializable]
public class Beverage
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int BeverageId { get; set; }
public int BeverageTypeId { set; get; }
public string Name { set; get; }
public string ImageUrl { get; set; }
public string Size { get; set; }
public string Details { get; set; }
public bool IsAvailableForGuests { get; set; }
public bool IsTaxable { get; set; }
public virtual BeverageType BeverageType { set; get; }
public virtual ICollection<BeveragePrice> BeveragePrices { set; get; }
}
The second model is BeveragePrice
[Serializable]
public class BeveragePrice
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int BeveragePriceId { set; get; }
[ForeignKey("Beverage")]
public int BeverageId { set; get; }
public Decimal Price { get; set; }
public double Taxes { get; set; }
public DateTime EffectiveDate { get; set; }
public virtual Beverage Beverage { set; get; }
}
BeveragePrice is a PartialView has its own model
<div class="form-horizontal">
<h4>Beverage Prices</h4>
<div class="col-md-6 col-sm-10">
<div class="form-group">
@Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "col-md-3 col-sm-4 control-label" })
<div class="col-md-8 col-sm-7">
@Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control", @type = "number", @step = "any", @onkeypress = "return OnlyNumeric(this);" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Taxes, htmlAttributes: new { @class = "col-md-3 col-sm-4 control-label" })
<div class="col-md-8 col-sm-7">
@Html.EditorFor(model => model.Taxes, new { htmlAttributes = new { @class = "form-control", @type = "number", @step = "any", @onkeypress = "return OnlyNumeric(this);" } })
</div>
<div class="measures">
<span>%</span>
</div>
</div>
</div>
<div class="col-md-6 col-sm-10">
<div class="form-group">
@Html.LabelFor(model => model.EffectiveDate, htmlAttributes: new { @class = "col-md-3 col-sm-4 control-label" })
<div class="col-md-8 col-sm-7 ">
<div class="form-control custominput">
@Html.EditorFor(model => model.EffectiveDate, "ClockDateTime", new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
</div>
</div>
<div style="clear:both"></div>
<div class="col-md-6 col-sm-10 col-right">
<div class="form-group">
<input type="button" value="Add Price" class="btn btn-primary">
</div>
</div>
</div>
As you see I have a button called addprice and another button to submit the form called create. What I want is when I click add price I validate only the price div and then I will add the price to a table under the price form because the user can add more than one price.