Paging in ASP.NET MVC part 2

by

Hi, again this is Part 2 from Paging in ASP.NET MVC.

In Part 1, I showed you how to add all data required.

Now let's try to finish what we start together.

Now will try to add new Controller and Call it StudentController.

The most important one is, what I highlight it (Yellow).

First one is declared our Interface,

  private readonly IStudent repositoryStudent;

building contractor.

 public StudentController(IStudent repoStudent)
        {
            repositoryStudent = repoStudent;
        }

 

This one our main job :)

ActionResult Index,

First int? page=1, this for your request, when it will be null, the default page will be first one page=1.

next step is reading data from our Repository.

  var model = repositoryStudent.GetStudent;

if no page was specified in the query string, default to the first page (1)

  var pageNumber = page ?? 1; 

 will only contain 25 products max because of the pageSize

  var onePageOfProducts = products.ToPagedList(pageNumber, 25); 
  

Don't forget to call X.PagedList .

using X.PagedList;

Now to our HTML code.

Just generate Index view.

next Photo will show you what you will have new change.

Again same what we call in our controller, we should call 2 library from X.PagedList.

@using X.PagedList.Mvc;  
@using X.PagedList;

after that to have a good style you need to add,

<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />

so after all that the most important part is.

@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page }))

 

The result will be same next photo.

 

 

 

Youtube Video.....

 

Hope this article is helpful.

If you have any question, just write in the comment.

 

Paging in ASP.NET MVC part 1

by

Hi,

Today I'm going to write about Paging in ASP.NET MVC.

First, if someone asks you about paging, why?

Sometimes, we have too many rows, Photos, articles and Products you don't want to display all of them in same time,

or let's say, you don't want load 100K row in one click, this will be a big issue with your application.

  So, the solution will be is paging.

and don't forget to use IQueryable rather than List or IEnumerable.

Now, To work our first step is to create new ASP.NET MVC Project.

Follow the Photos.

 

Choose MVC,

 

Next Step, Add X.PagedList  From NuGet packages.

So, Now we need data to send it to our HTML page and display it in the table.

First, we need to create new Class in Models folder and call it Student.

 

Next Step, Create Folder Call it Services will put inside it,

a new class (IStudent class).

 

 

After Create our Interface, we need to create Repository Folder with StudentRepository class.

In StudentRepository Class, I have fake data just to show you how it will be in our HTML page.

sure you can Use data from your SQL Server database, using Entry Framework.

 

Part2

ASP.NET Web Service

by

ASP.NET Web Service 

?????? ????? ????? ???? ??????? .

?? ????? ?????? ??  ?? ??????? ?? ????? ????? Web Service   .

??????? , ?????? ????????? ?? ??? ??????? ?? ????? ??? , ????? ??????? ????? ?? ??????? ????? ???? ?? ?????? ??? ???? ?????? ?? ASP.NET Web Service  .

?? ??? ????? ??? Java  ?? PHP  .

??? ?? ???? ????? ????? , ??????? ???? ????? ??? ???? ??????? , ?????????? ?? ?? ???????? ?? ??? ??????? .

- ?? ?????? ?? ??? ??? ???? ???  , ??? ???? ?????? Yahoo  , ?? ?? ???? ??? .

??? ?? ?????? ???? ????? , ?? ???? ?????? ??????? ......

??? ?? ????? ????? , ??? ???? ?????? ??????? ???? ????? ????? , ????? ???????? ,

???? ????? ????? ,?????? ?????? ........

????? ????? ??? ???? ?? ASP.NET Web Service  .

- ??? ????? , ?? ?? Hello World  .

--???? ????? ?????? , ????? ????? ???? .

 

?? ???? ????? ???? .....

 

???? ??? ??????? ?????? ?????? ....

??? ????? ??????? ?????? , ???? ??????  ??? ?????? ??? ?? ?????? ??????? :

 

???? ??? ????? ?????? , ????? ???????? .

 

???? ??? ????? ?????? , ??? ???? ?? ?????? ??????? ???? ???? ???? Helloworld  ??? ?????? ??? ?? ???? ???? Hello World  .

 

??? ????? ??? Helloworld  . ??? ????? ??? XML , ???????? .

 

???? ????? ?? ???? , ?? ??? , ??? ????????  , ???? ??????? ??????? .

- ??? ??? ??? ????? .

??? ???? ?????? ??????? , ?????? ADD  ???? ???? A  ? b  ?????? ?????? .

???? Run  .

???? ????? ???????? Helloworld  ? Add  .

 

?????? ?????? ADD   , ???? ?????? ??????? ,, ????? ????? ?? a and b  ??? ?? Invoke

 

?????? ?? ::

?

 

 

???? ???? ???? , ???? ????????? ??? , ?? ????? Projects  .

 

 

Using the DropDownList with ASP.NET MVC Razor

by

السلام عليكم ,

في المقالة التالية سيتم شرح كيفية تركيب  

DropDownList with ASP.NET MVC  .

سيكون المثال عبارة عند جلب البيانات من   SQL Server  واظهارها في ASP.NET MVC Page   .

الجداول التالية في SQL Server 

Employees

Gender 

تعرف الحقول التاليه في C#  , كما هو مبين :

من اجل 

Employee Table  .

  Gender Table  .

 

تهيئة  EmployeeController  . من اجل العمل مع الداتا بير .

 

الشكل الذي سوف يظهر لدينا عند تشغيل المشروع  :

 

Code  GitHub

Load Me ASP.NET MVC 5 AJAX

by

Load Me ASP.NET MVC 5 AJAX  

 

السلام عليكم ,

في المثال التالي سوف نحاول استخدام AJAX  مع ASP.NET MVC  , واظهار موشر مشغولية المعالج , في اثناء تنفيذ اي عمليه.

 

 public class EmployeeController : Controller    {        private readonly IEmployee _Employee;        public EmployeeController(IEmployee employee)        {            _Employee = employee;        }        // GET: Employee        public ActionResult Index()        {            return View();        }        [HttpGet]        public ActionResult GetEmployees()        {           return PartialView("_GetEmployees", _Employee.GetEmployee);        }    }

 

Index Pege :

 

@{    ViewBag.Title = "Index";}<link href="~/Content/loadme.css" rel="stylesheet" />@{    var options = new AjaxOptions()    {        UpdateTargetId = "DivContent",        InsertionMode = InsertionMode.Replace,        HttpMethod = "Get",        OnBegin = "onLoadBegin",        OnSuccess = "onLoadSuccess"    };}<br/>@Ajax.ActionLink("Employees", "GetEmployees", "Employee", options,new { @class = "btn btn-primary" })<hr/><div id="DivContent">    Your PartialView Will be here. </div><div id="divLoading" style="display:none">    <div class="loadmeRect">        <div class="loadmeRectChild loadmeRect1"></div>        <div class="loadmeRectChild loadmeRect2"></div>        <div class="loadmeRectChild loadmeRect3"></div>        <div class="loadmeRectChild loadmeRect4"></div>        <div class="loadmeRectChild loadmeRect5"></div>    </div>    <div class="loadme-mask"></div></div>

 

partial View

 

@model IEnumerable<TestLoadMeAjax.Models.Employee><p>    @Html.ActionLink("Create New", "Create")</p><table class="table">    <tr>        <th>            @Html.DisplayNameFor(model => model.Name)        </th>        <th>            @Html.DisplayNameFor(model => model.Gender)        </th>        <th>            @Html.DisplayNameFor(model => model.Salary)        </th>        <th></th>    </tr>@foreach (var item in Model) {    <tr>        <td>            @Html.DisplayFor(modelItem => item.Name)        </td>        <td>            @Html.DisplayFor(modelItem => item.Gender)        </td>        <td>            @Html.DisplayFor(modelItem => item.Salary)        </td>        <td>            @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-warning" })|            @Html.ActionLink("Details", "Details", new { id=item.Id }, new { @class = "btn btn-warning" }) |            @Html.ActionLink("Delete", "Delete", new { id=item.Id }, new { @class = "btn btn-warning" })        </td>    </tr>}</table>

Code GitHub