Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
@{
    Layout = "~/Views/Account/_AccountLayout.cshtml";
}
@model List<SportsStore.Models.Tbl_Order>
<fieldset>
    <div style="margin-top: 50px">
        @{
 
            var grid = new WebGrid(Model, defaultSort: "Name");
 
        }
        @if (Model.Count > 0)
        {
            @grid.GetHtml(
    columns: grid.Columns(
                      grid.Column(format: (item) => Html.ActionLink("Product Detail", "OrderDetail", new { id = item.OrderId })),

                                           grid.Column("OrderId", format: (item) => Html.ActionLink((string)item.OrderId.ToString(), "OrderDetail", new { id = item.OrderId })),
            grid.Column("Orderdate"),

    grid.Column("LastName", header: "Last Name"),
            grid.Column("CartTotal"),
            grid.Column("TransactionId", header: "Payment Id"),
            grid.Column("Status", header: "Payment Status")
            )
            )
           
        }
        else
        {
            <div style="width: 500px">
                <h3>
                    @ViewBag.Name</h3>
            </div>
        }
    </div>
</fieldset>


C#
[HttpGet]
     public ActionResult OrderDetail(int? OrderId)
     {
         List<OrderDetail> _objOrderDetail = new List<OrderDetail>();
         OrderDetailContext _OrderDetailContext = new OrderDetailContext();
         _objOrderDetail = _OrderDetailContext.OrderDetailEntries.Where(c => c.OrderId == OrderId).ToList();
         return View();
     }

Hi,

I want to display order details when i will click order id, but I see in C#(Controller) that there my id is null.
And also paging in grid if possible for you (customize paging ).

Please help me.


Thanks
Anil
Posted
v3

well the "106" is the correct id but try to modify your webgrid like this :
C#
grid.Column(header: "Details", format:  (item) =>                         Html.ActionLink("OrderDetail", "OrderDetail", new { id = item.OrderId }))
 
Share this answer
 
v3
Hi

I am not sure about it

i get the url like
localhost:94424/Account/Orderdetail/106


when i see the order details

and i get orderid
using the following code


C#
string s = Request.Url.ToString();

            string str = s.Remove(s.LastIndexOf("/"));

            Int32 orderid = Convert.ToInt32(s.Replace(str, "").ToString().Replace("/", ""));



Its right way or not please guide me

Thanks in Advance
 
Share this answer
 
Hi Hedi ,

i have change my View but still i get the OrderId null in Controller
this is my Action
C#
public ActionResult OrderDetail(int? OrderId)
{

}


i think i missing something other but i dont know what i missing there
if you have any suggestion .
Please tell me

Thanks - Anil
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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