say, I have a class library name CustomObject. This library holds objects. one of them is Product
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ObjectLayer
{
[Serializable]
public class Products
{
private int _Id;
private string _ProductName;
private string _ProductMakers;
private int _Price;
private OrderPlacementModes _ActionTaken;
public Products()
{
Id = 0;
ProductName = string.Empty;
ProductMakers = string.Empty;
Price = 0;
ActionTaken = OrderPlacementModes.NoAction;
}
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public string ProductName
{
get
{
return _ProductName;
}
set
{
_ProductName = value;
}
}
public string ProductMakers
{
get
{
return _ProductMakers;
}
set
{
_ProductMakers = value;
}
}
public int Price
{
get
{
return _Price;
}
set
{
_Price = value;
}
}
public OrderPlacementModes ActionTaken
{
get { return _ActionTaken; }
set { _ActionTaken = value; }
}
}
}
solution has another project which holds BAL (Business Access Layer) and a DAL (Data Access Layer)
I did in Controller is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ObjectLayer;
using OrderPlacementBLL;
namespace MvcApplication1.Controllers
{
public class ProductssController : Controller
{
public ActionResult Index()
{
return View(new ProductsBLL().GetAllProducts());
}
[HttpPost]
public ActionResult Index(FormCollection ProductList)
{
return View();
}
}
}
and in view
@model List<ObjectLayer.Products>
<h2>
Index</h2>
@using (Html.BeginForm("Index", "Productss", FormMethod.Post, null))
{
foreach (var item in Model)
{
<legend>
<fieldset>
Id: @Html.TextBoxFor(txt => item.Id)<br />
Prict: @Html.TextBoxFor(txt => item.Price)<br />
Makers: @Html.TextBoxFor(txt => item.ProductMakers)<br />
Product Name: @Html.TextBoxFor(txt => item.ProductName)<br />
</fieldset>
</legend>
}
<input type="submit" value="Submit" />
}
now I want, when I pressed submit button, all the data (List<products>) should be submitted to the controller with changes. please help