Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $("#add-more").click(function() {
- selectedColor = $("#select-color option:selected").val();
- if (selectedColor == '')
- return;
- var color = ' <
- div class = "form-group" >
- <
- label class = "col-md-2 control-label" > Color: < /label> <
- div class = "col-md-5" > < label class = "control-label" > ' + selectedColor + ' < /label></div >
- <
- /div>
- ';
- var sizeAndQuantity = ' <
- div class = "form-group" >
- <
- label class = "col-md-2 control-label" > Size and Quantity: < /label> <
- div class = "col-md-2" > < label class = "control-label" > S < /label><input type="text" class="form-control"></div >
- <
- div class = "col-md-2" > < label class = "control-label" > M < /label><input type="text" class="form-control"></div >
- <
- div class = "col-md-2" > < label class = "control-label" > L < /label><input type="text" class="form-control"></div >
- <
- div class = "col-md-2" > < label class = "control-label" > XL < /label><input type="text" class="form-control"></div >
- <
- /div>
- ';
- html = color + sizeAndQuantity
- $("#appendTarget").append(html)
- });
- });
- namespace ProjectSem3.Areas.Admin.Models
- {
- public class ProductViewModel
- {
- public ProductGeneral ProductGeneral { get; set; }
- public List<SizeColorQuantityViewModel> SizeColorQuantities { get; set; }
- }
- public class ProductGeneral
- {
- public string Product { get; set; }
- public string Description { get; set; }
- public string ShortDescription { get; set; }
- public List<ProductCategory> Categories { get; set; }
- public string SKU { get; set; }
- public float Price { get; set; }
- public float PromotionPrice { get; set; }
- public bool Status { get; set; }
- }
- public class SizeColorQuantityViewModel
- {
- public string ColorId { get; set; }
- public List<SizeAndQuantity> SizeAndQuantities { get; set; }
- }
- public class SizeAndQuantity
- {
- public string SizeId { get; set; }
- public int Quantity { get; set; }
- }
- }
- public class ProductController : Controller
- {
- // GET: Admin/Product
- public ActionResult Create()
- {
- var colors = new List<string>() { "Red", "Blue" };
- var sizes = new List<string>() { "S", "M", "L", "XL" };
- var categories = new ProductDao().LoadProductCategory();
- var productGeneral = new ProductGeneral()
- {
- Categories = categories
- };
- var model = new ProductViewModel
- {
- ProductGeneral = productGeneral,
- SizeColorQuantities = new List<SizeColorQuantityViewModel>()
- };
- foreach (var color in colors)
- {
- var child = new SizeColorQuantityViewModel
- {
- ColorId = color,
- SizeAndQuantities = new List<SizeAndQuantity>()
- };
- model.SizeColorQuantities.Add(child);
- foreach (var size in sizes)
- {
- child.SizeAndQuantities.Add(new SizeAndQuantity()
- {
- SizeId = size
- });
- }
- }
- return View(model);
- }
- // POST: Admin/Product
- [HttpPost]
- public ActionResult Create(ProductViewModel model)
- {
- return View();
- }
- }
- @for (var i = 0; i < Model.SizeColorQuantities.Count; i++)
- {
- <div class="form-group">
- <label class="col-md-2 control-label">Color:</label>
- <div class="col-md-2">
- @Html.TextBoxFor(m => m.SizeColorQuantities[i].ColorId, new { @class = "form-control", @readonly = "readonly" })
- </div>
- </div>
- <div class="form-group">
- <label class="col-md-2 control-label">Size and Quantity:</label>
- @for (var j = 0; j < Model.SizeColorQuantities[i].SizeAndQuantities.Count; j++)
- {
- <div class="col-md-2">
- @Html.TextBoxFor(m => m.SizeColorQuantities[i].SizeAndQuantities[j].SizeId, new
- {
- @class = "form-control",
- @style = "margin-bottom: 15px",
- @readonly = "readonly"
- })
- @Html.TextBoxFor(m => m.SizeColorQuantities[i].SizeAndQuantities[j].Quantity, new { @class = "form-control" })
- </div>
- }
- </div>
- }
Add Comment
Please, Sign In to add comment