I am pretty new to ASP.Net MVC. Sorry if my question seems stupid. but I am not sure how to get things to work between views and controllers.
I have a product list with the price and have static drop down to implement discount strategies based on discount plan selected.
Here is my product page
<pre><table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.ProductPrice)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductPrice)
</td>
<td>
@Html.DropDownList("Status", new List<SelectListItem>
{
new SelectListItem{ Text="Student Discount", Value = "1" },
new SelectListItem{ Text="Loyalty Discount", Value = "0" }
})
</td>
<
here is my Add product Controller
public ActionResult Index()
{
Customers customer = new Customers();
return View(db.Products.ToList());
}
What I have tried:
I want to show discounted price on the page based on the selection from the dropdown.
I am implementing this windows form application stretegy in my MVC application .
But i am not sure how to handle it in views and controller.
Any hints would be appreciated.
here is the code from windows form applicaion
private void btnApplyDiscounts_Click(object sender, EventArgs e)
{
Customer customer = new Customer();
if (chkLoyalty.Checked && chkStudent.Checked)
{
customer.SetDiscountStrategy(new LoyalStudentDiscount());
}
else if (chkLoyalty.Checked)
{
customer.SetDiscountStrategy(new LoyaltyDiscount());
}
else if (chkStudent.Checked)
{
customer.SetDiscountStrategy(new StudentDiscount());
}
else
{
customer.SetDiscountStrategy(new NoDiscount());
}
decimal price = customer.ApplyDiscount(numTotalSale.Value);
lblFinalPrice.Text = price.ToString("C");
}
}
}