I am gonna submit the form everytime when checkbox clicked later but for now I need to pass the data if checkboxes are false or true but data never goes to my PriceRange post method. Thanks.
this is my controller. I pass data to my view with this obj.
public class HomeController : Controller
{
private FilizTakiEntityDB db = new FilizTakiEntityDB();
public ActionResult Index()
{
Anasayfa obj = new Anasayfa();
obj.products = db.Products.ToList();
obj.priceRange = db.PriceRange.ToList();
return View("Index", obj);
}
[HttpPost]
public ActionResult PriceRange(PriceRange prc , int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var mevcut = db.PriceRange.Find(id);
mevcut.Fiyat1 = prc.Fiyat1;
mevcut.Fiyat2 = prc.Fiyat2;
mevcut.Fiyat3 = prc.Fiyat3;
return View("Index");
}
}
public class Anasayfa
{
public List<PriceRange> priceRange { get; set; }
public List<Products> products { get; set; }
}
this is my view:
@model FilizTakiProject.Controllers.Anasayfa
@using (Html.BeginForm("PriceRange", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
foreach (var x in Model.priceRange)
{
@Html.CheckBoxFor(ModelItem=>x.Fiyat1)<br />
@Html.CheckBoxFor(ModelItem => x.Fiyat2)<br />
@Html.CheckBoxFor(ModelItem => x.Fiyat3)
}
<input type="submit" name="submit" value="Submit" />
}
this is my model
public partial class PriceRange
{
public int PriceID { get; set; }
public bool Fiyat1 { get; set; }
public bool Fiyat2 { get; set; }
public bool Fiyat3 { get; set; }
}