Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
HTML
<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");
        }
    }
}
Posted
Updated 4-Mar-17 13:38pm
Comments
F-ES Sitecore 6-Mar-17 4:51am
   
You can't always "convert" a Windows Forms app to a website with ease, you need to appreciate the difference between a Windows app and a website. In the Windows app the GUI and business logic etc are all controlled by your .net code and your .net code is fully event driven. In a web app your .net code only really gets "events" via page post-backs and your .net code only creates the initial html page, after that the front end can only be dynamically manipulated via javascript.

1 solution

Razor is a server-side html rendering engine. So before the page is sent to the user's web browser.

If you want to make changes client-side, after the page is loaded in the browser, then you will need to use javascript/jquery/etc...
   
v2
Comments
codegeekalpha 4-Mar-17 20:47pm
   
is it not possible with razor and C# only?
Graeme_Grant 4-Mar-17 21:06pm
   
The question to ask yourself is "Do I want to do it client side or server side?" If client, then javascript as mentioned already.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900