Seach in MVC5 RRS feed

  • Question

  • .Dear all,

    I am a newbie in MVC5, I want to make an application to search activities score for <g class="gr_ gr_1616 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" data-gr-id="1616" id="1616">student</g>.

    When I input Student ID into the textbox then press Seach button. I want to show Name, Class of student and the list of their activities. How to do that? Please help me. I show the controller and view. My database has 3 table: student, Activity, and Grading.

    Thank you so much!

    public ActionResult Index(string filter_value, string Sid, int? page) { ViewBag.Message = "Please enter your ID number"; if (Sid != null) { page = 1; } else { Sid = filter_value; } ViewBag.FilterValue = Sid; var grad = db.Gradings.ToList(); if (!string.IsNullOrEmpty(Sid)) { grad = db.Gradings.Include(g => g.Activity).Include(g => g.Student).Where(g => g.StudentID == Sid).ToList(); ViewBag.Total = grad.Sum(g => g.Score); } int Page_of_size = 5;

    int page_of_number = (page ?? 1); return View(grad.OrderBy(g => g.Activity.Name).ToPagedList(page_of_number, Page_of_size)); }

    and View index.cshtml:

    @model PagedList.IPagedList<ActivityScore.Models.Grading>
    @using PagedList.Mvc;
    <link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
        ViewBag.Title = "Index";
    <div class="jumbotron">
        <h2>5 Activities </h2>
    <div class="row">
        <div class="col-xs-3">
            <h2>Top 5 Student highest score</h2>
            <p><a class="btn btn-default" href="">Learn more &raquo;</a></p>
        <div class="col-xs-4">
                @using (Html.BeginForm())
                    Student ID: @Html.TextBox("Sid", ViewBag.FilterValue as string)
                    <input type="submit" value="Search" />
                <table class="table">
                        <th>Activity Name</th>
                        <th> Score</th>
                        <th> Note </th>
                    @foreach (var item in Model)
                            <td> @Html.DisplayFor(modelItem => item.Activity.Name)</td>
                            <td>@Html.DisplayFor(modelItem => item.Responsibility)</td>
                            <td> @Html.DisplayFor(modelItem => item.Score)  </td>
                            <td>@Html.DisplayFor(modelItem => item.Note) </td>
                <br />
                Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
                @Html.PagedListPager(Model, page => Url.Action("Index", new { page, Filter_Value = ViewBag.FilterValue }))
                <br />
                <h3> Total score: @ViewBag.Total</h3>

    • Moved by CoolDadTx Wednesday, December 6, 2017 2:55 PM ASP.NET related
    Thursday, November 30, 2017 9:54 AM

All replies

  • ASP.NET MVC can be discussed at the below forum.


    Thursday, November 30, 2017 11:17 AM
  • Thanks for your information.
    Friday, December 1, 2017 4:32 AM
  • Hi oraika,

    Thank you for posting here.

    According to your question is more related to MVC, you could post a new thread in MVC forum for suitable support.

    This forum discusses and ask the C# programming language, IDE, libraries, samples and tools. If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 1, 2017 5:24 AM