Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

This is my order page. I have problem on "Add Product" that when i click it, Products don't appear in below grid. I give my OrderController code which related to "Add Product" :

C#
public ActionResult AddProduct()
     {
         List<OrderDetailViewModel> orderDetails =
             (List<OrderDetailViewModel>)Session["OrderDetails"];

         OrderDetailViewModel vm = new OrderDetailViewModel();

         vm.ProductId = Convert.ToInt32(Request["AddProductId"]);
         vm.ProductName = Convert.ToString(Request["AddProductName"]);
         vm.Quantity = Convert.ToInt32(Request["AddQuantity"]);
         vm.UnitPrice = Convert.ToDecimal(Request["AddUnitPrice"]);

         orderDetails.Add(vm);

         return RedirectToAction("Create");
     }


and please also you can find view code:
HTML
<div id="pnlProductAdd">
    <form action="@Url.Action("AddProduct","Order")" id="frmProductAdd" method="post">
        <div class="row">
            <div class="col-md-3">
                Product: <select id="txtAddProductId" name="AddProductId">
                    <option value="">-- Select --</option>
                    @foreach (var product in Model.Products)
        {
                        <option value="@product.ProductID">@product.ProductName</option>
                    }
                </select>
            </div>
            <div class="col-md-3">
                Quantity: <input type="text" name="AddQuantity" id="txtAddQuantity" />
            </div>
            <div class="col-md-3">
                Price: <input type="text" name="AddUnitPrice" id="txtAddUnitPrice" />
            </div>
            <div class="col-md-3">
                <input type="button" id="btnAddProduct" value="Add Product" />
            </div>
        </div>
    </form>
</div>


What I have tried:

I have tried "selectlist" code on ordercontroller to solve this issue but i could not succeed. I think this code - vm.ProductName = Convert.ToString(Request["AddProductName"]); - that are mentioned in ordercontroller need to be modified.
Posted
Updated 5-Jun-16 1:48am
v2
Comments
George Jonsson 5-Jun-16 1:06am    
So what is your problem?
How to read data from a database?
gokhan572 5-Jun-16 7:49am    
Dear George, I have explained my issue in detail. Could you please check it again?
If anythingelse that is not clear, please let me know.
George Jonsson 5-Jun-16 8:30am    
Sorry, I'm not proficient in MVC.
Just wanted you explain your problem in more detail, which you have done now.
If that is enough for someone to help you with a solution remains to be seen.

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