Learn how to use MVC4 for website 5: 5.2 my articles

Source: Internet
Author: User
Tags actionlink

The Document Management Section is written down according to the left-side navigation section.

To the "my articles" section.

Open [ArticleController] and add public ActionResult UserOwn (int id = 0, int page = 1)

The id here refers to the column id, which can display the articles in the specified column published by yourself. The default value is 0, indicating that there are articles in the column, and the page number is 1 by default.

There is nothing here, mainly called.

Learning to use MVC4 for website 4: List function of public model CommonModelRepository.
/// <Summary> /// my article /// </summary> /// <param name = "id"> topic id </param> /// <param name = "page"> page number </param> [UserAuthorize] public ActionResult UserOwn (int id = 0, int page = 1) {int _ pageSize = 20; int _ cOrder = 0; Category _ c = null; cModelRsy = new CommonModelRepository (); PagerData <CommonModel> _ aData; if (id> 0) {var _ cRsy = new CategoryRepository (); _ c = _ cRsy. find (id); if (_ c! = Null) {_ pageSize = (int) _ c. pageSize; _ cOrder = (int) _ c. contentOrder ;}}_ aData = cModelRsy. list (id, false, "Article", UserController. userName, page, _ pageSize, _ cOrder); if (_ c! = Null) {_ aData. Config. RecordName = _ c. RecordName; _ aData. Config. RecordUnit = _ c. RecordUnit;} return View (_ aData );}

Right-click to add a strong view. The model class is PagerData <Ninesky. models. commonModel> (this option is not available in the add model class. When I wrote the paging control, I wanted to separate the paging control and wrote the PagerData class in the Mvc space, no view is selected here. Write @ model PagerData <Ninesky at the top of the added View File. models. commonModel>)

The View File is also very simple. Instead of a table, @ foreach cyclically adds the table content and adds Html. Pager pages at the bottom.

@ Model PagerData <Ninesky. Models. CommonModel> @ {ViewBag. Title = "my article"; Layout = "~ /Views/Shared/_ User. cshtml ";}< div class =" workspace "> <div class =" inside "> <div class =" notebar ">  your current location: article management </div> <table class = "modelitems_table"> <tr> <th> ID </th> <th> column </th> <th> title </th> <th> issuer </th> <th> release time </th> <th> Status </th> <th> click </th> <th colspan = "2"> operation </th> </tr> @ foreach (var item in Model) {<tr> <td> @ item. commonModelId </td> <td> [@ Html. actionLink (item. category. name, "UserOwn", new {id = item. categoryId})] </td> <td class = "title"> @ item. title </td> <td> @ item. inputer </td> <td> @ item. releaseDate </td> <td> @ Ninesky. models. commonModel. contentStatus. firstOrDefault (c => c. value = item. status. toString ()). text </td> <td> @ item. hits </td> <td> @ Html. actionLink ("modify", "UserEdit", new {id = item. commonModelId}) </td> <a> Delete </a> </td> </tr >}</table> @ Html. pager (this. viewContext. routeData. values, Model. config, "pager", "pager") </div> <div class = "left"> @ Html. partial ("PartialUserNavMenus") <br/> </div> <div class = "clear"> </div>

F5

For the code, see:

Learn how to use MVC4 for website 5: articles

======================================

Finally, I would like to thank my brothers and sisters for their support. I am a hobbyist and have not been engaged in software since I graduated so many years. I want to learn something in my spare time. I think it is quite dynamic to see your team's attention and comments. Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.