{"id":176063,"date":"2013-04-09T22:56:13","date_gmt":"2013-04-09T18:56:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=176063"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=176063","title":{"rendered":"<span class=\"post_title\">ASP.NET MVC \u0423\u0440\u043e\u043a 8. View, Razor, \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043e\u0448\u0438\u0431\u043a\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430<\/b>. \u041d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 html, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Razor. Helper\u044b. PageableData. \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u044b. RedirectToLogin, RedirectToNotFoundPage. \u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043e\u0448\u0438\u0431\u043a\u0438. RssActionResult.<\/p>\n<h5>\u041e\u0441\u043d\u043e\u0432\u0430<\/h5>\n<p>  \u0418\u0442\u0430\u043a, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0447\u0430\u0441\u0442\u044c View.<br \/>  \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0432\u0441\u0435 action-\u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0442\u0438\u043f ActionResult. \u0418 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<br \/>  <code>return View(modelData);<\/code><\/p>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 View \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c:  <\/p>\n<ul>\n<li>\u0418\u043c\u044f, \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c action-\u043c\u0435\u0442\u043e\u0434\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u043d\u043e\u0439 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 View, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>return View(\u201cViewName\u201d, modelData).<\/code><\/li>\n<li>\u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e View. \u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0432\u043e View \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c\u0441\u044f Model. \u0414\u043b\u044f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e View \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445:<br \/> \n<pre><code>\t@model LessonProject.Model.User <\/code><\/pre>\n<p>  <\/li>\n<li>Layout. \u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440. \u041f\u0440\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f. View-\u0447\u0430\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u043c RenderBody()<\/li>\n<\/ul>\n<p>  \u0412\u044b\u0431\u043e\u0440, \u043a\u0430\u043a\u043e\u0439 \u0436\u0435 View \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<ul>\n<li>\u0418\u0449\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 \/Areas\/[Area]\/Views\/[ControllerName]\/<\/li>\n<li>\u0418\u0449\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 \/Areas\/[Area]\/Views\/Shared\/<\/li>\n<li>\u0418\u0449\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 \/Views\/[ControllerName]\/<\/li>\n<li>\u0418\u0449\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 \/Views\/Shared\/<\/li>\n<\/ul>\n<p>  \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044e.<\/p>\n<h5>Razor<\/h5>\n<p>  \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 View \u0435\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0434\u0432\u0438\u0436\u043a\u0430\u043c\u0438: ASPX \u0438 Razor. \u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e Razor.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/c06\/f16\/873\/c06f16873cf42c20c35a65082118965f.jpg\"\/><\/p>\n<p>  ASPX \u0431\u044b\u043b \u0433\u0440\u043e\u043c\u043e\u0437\u043a\u0438\u043c \u0434\u0432\u0438\u0436\u043a\u043e\u043c \u0441 \u0442\u0435\u0433\u0430\u043c\u0438 <code>&lt;% %&gt;<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0438 <code>&lt;%: %&gt;<\/code> \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  Razor \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>@Model.Name<\/code>. \u0422.\u0435. \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 <code>@<\/code> \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0432 \u0440\u0435\u0436\u0438\u043c \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0438\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <code>@foreach() {\u2026}<\/code>, \u0438\u043b\u0438 <code>@if() { \u2026 } else { \u2026 }<\/code>:<\/p>\n<pre><code class=\"html\">@if (Model.Any()) { &lt;p&gt;\u0421\u043f\u0438\u0441\u043e\u043a&lt;\/p&gt;     }  @foreach (var role in Model)     {         &lt;div class=&quot;item&quot;&gt;             &lt;span class=&quot;id&quot;&gt;                 @role.ID             &lt;\/span&gt;             &lt;span class=&quot;name&quot;&gt;                 @role.Name             &lt;\/span&gt;             &lt;span class=&quot;Code&quot;&gt;                 @role.Code             &lt;\/span&gt;         &lt;\/div&gt;     } <\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 { } \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0442\u0435\u0433\u0438 \u2013 \u044d\u0442\u043e \u043c\u0430\u0440\u043a\u0435\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 @{ code }, \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438\u043b\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u2014 @(string result):  <\/p>\n<pre><code class=\"html\"> @{         int i = 0;     }     @foreach (var role in Model)     {         &lt;div class=&quot;item @(i % 2 == 0 ? &quot;odd&quot; : &quot;&quot;)&quot;&gt;             &lt;span class=&quot;id&quot;&gt;                 @role.ID             &lt;\/span&gt;             &lt;span class=&quot;name&quot;&gt;                 @role.Name             &lt;\/span&gt;             &lt;span class=&quot;Code&quot;&gt;                 @role.Code             &lt;\/span&gt;         &lt;\/div&gt;         i++;     } <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0435 \u0442\u0435\u0433\u043e\u0432\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0441\u0435\u0432\u0434\u043e\u0442\u0435\u0433\u0438 <code>&lt;text&gt;&lt;\/text&gt;<\/code>:  <\/p>\n<pre><code class=\"html\">@foreach (var role in Model)     {        @role.Name&lt;text&gt;, &lt;\/text&gt;     } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 html-\u0442\u0435\u043a\u0441\u0442\u0430 \u2013 \u0438\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f MvcHtmlString, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <a href=\"http:\/\/habrahabr.ru\/users\/html\/\" class=\"user_link\">Html<\/a>.Raw(html-string-value), \u0438\u043d\u0430\u0447\u0435 \u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0441 \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u0435\u0433\u043e\u0432. <\/p>\n<h5>PageableData <\/h5>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0437 \u0411\u0414. \u041f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c:   <\/p>\n<ol>\n<li>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c <\/li>\n<li>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430<\/li>\n<li>\u041f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c:<br \/> \n<ol>\n<li>\u0421\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0411\u0414, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c<\/li>\n<li>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446<\/li>\n<li>\u0422\u0435\u043a\u0443\u0449\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/li>\n<\/ol>\n<p>  <\/li>\n<\/ol>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c Generic-\u043a\u043b\u0430\u0441\u0441 PageableData (\/Models\/Info\/PageableData.cs):  <\/p>\n<pre><code class=\"cs\">public class PageableData&lt;T&gt; where T : class     {         protected static int ItemPerPageDefault = 20;          public IEnumerable&lt;T&gt; List { get; set; }          public int PageNo { get; set; }          public int CountPage { get; set; }          public int ItemPerPage { get; set; }          public PageableData(IQueryable&lt;T&gt; queryableSet, int page, int itemPerPage = 0)         {             if (itemPerPage == 0)             {                 itemPerPage = ItemPerPageDefault;             }             ItemPerPage = itemPerPage;              PageNo = page;             var count = queryableSet.Count();              CountPage = (int)decimal.Remainder(count, itemPerPage) == 0 ? count \/ itemPerPage : count \/ itemPerPage + 1;             List = queryableSet.Skip((PageNo - 1) * itemPerPage).Take(itemPerPage);         }     } <\/code><\/pre>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u2013 20, \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c IQueryable \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 CountPage. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f PageNo, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443:  <\/p>\n<pre><code class=\"cs\">List = queryableSet.Skip((PageNo - 1) * itemPerPage).Take(itemPerPage); <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:  <\/p>\n<pre><code class=\"cs\">public class UserController : DefaultController     {         public ActionResult Index(int page = 1)         {             var data = new PageableData&lt;User&gt;(Repository.Users, page, 30);             return View(data);         } \u2026 <\/code><\/pre>\n<p>  \u0412\u043e View \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:  <\/p>\n<pre><code class=\"html\">@model LessonProject.Models.Info.PageableData&lt;LessonProject.Model.User&gt;  @{     ViewBag.Title = &quot;Users&quot;;     Layout = &quot;~\/Areas\/Default\/Views\/Shared\/_Layout.cshtml&quot;; }  &lt;h2&gt;Users&lt;\/h2&gt;  &lt;p&gt;     @foreach (var user in Model.List)     {         &lt;div class=&quot;item&quot;&gt;             &lt;span class=&quot;id&quot;&gt;                 @user.ID             &lt;\/span&gt;             &lt;span class=&quot;email&quot;&gt;                 @user.Email             &lt;\/span&gt;             &lt;span class=&quot;activateDate&quot;&gt;                 @user.AddedDate             &lt;\/span&gt;         &lt;\/div&gt;     } &lt;\/p&gt;  <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c (http:\/\/localhost\/User)<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/e4c\/e4d\/b78\/e4ce4db78b65cbdfa86ef9e87f941303.jpg\"\/><\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u0440\u043e\u0441\u0442\u043e ctrl-c, ctrl-v \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432 Server Explorer)<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/005\/973\/135\/005973135f525f7f9461170d04c652b1.jpg\"\/><\/p>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e Helper\u2019\u0430 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<h5>Helper (PagerHelper)<\/h5>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c bootstrap, \u0442\u043e \u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440. \u0412 \u043a\u043e\u0434\u0435 \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"html\">&lt;div class=&quot;pagination&quot;&gt;         &lt;ul&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Prev&lt;\/a&gt;&lt;\/li&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;1&lt;\/a&gt;&lt;\/li&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;2&lt;\/a&gt;&lt;\/li&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;3&lt;\/a&gt;&lt;\/li&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;4&lt;\/a&gt;&lt;\/li&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;5&lt;\/a&gt;&lt;\/li&gt;             &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Next&lt;\/a&gt;&lt;\/li&gt;         &lt;\/ul&gt;     &lt;\/div&gt; <\/code><\/pre>\n<p>  \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0447\u0430\u0441\u0442\u044c <code>&lt;ul&gt;&lt;\/ul&gt;<\/code>. <br \/>  Helper \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a Extension \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 System.Web.Mvc.HtmlHelper. \u041f\u043b\u0430\u043d \u0442\u0430\u043a\u043e\u0432:  <\/p>\n<ul>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 Prev (\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e)<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0442\u0440\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b 1, 2, 3<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0440\u043e\u0435\u0442\u043e\u0447\u0438\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b <\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0440\u043e\u0435\u0442\u043e\u0447\u0438\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0442\u0440\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 Next (\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e)<\/li>\n<li>\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0451 \u0432 ul \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u0430\u043a MvcHtmlString<\/li>\n<\/ul>\n<p>  \u041a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">public static MvcHtmlString PageLinks(this HtmlHelper html, int currentPage, int totalPages, Func&lt;int, string&gt; pageUrl)         {             StringBuilder builder = new StringBuilder();              \/\/Prev             var prevBuilder = new TagBuilder(&quot;a&quot;);             prevBuilder.InnerHtml = &quot;&laquo;&quot;;             if (currentPage == 1)             {                 prevBuilder.MergeAttribute(&quot;href&quot;, &quot;#&quot;);                 builder.AppendLine(&quot;&lt;li class=\\&quot;active\\&quot;&gt;&quot; + prevBuilder.ToString() + &quot;&lt;\/li&gt;&quot;);             }             else             {                 prevBuilder.MergeAttribute(&quot;href&quot;, pageUrl.Invoke(currentPage - 1));                 builder.AppendLine(&quot;&lt;li&gt;&quot; + prevBuilder.ToString() + &quot;&lt;\/li&gt;&quot;);             }             \/\/\u041f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443             for (int i = 1; i &lt;= totalPages; i++)             {                 \/\/\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0447\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u043e\u043c\u0435\u0440\u0430                 if (((i &lt;= 3) || (i &gt; (totalPages - 3))) || ((i &gt; (currentPage - 2)) && (i &lt; (currentPage + 2))))                 {                     var subBuilder = new TagBuilder(&quot;a&quot;);                     subBuilder.InnerHtml = i.ToString(CultureInfo.InvariantCulture);                     if (i == currentPage)                     {                         subBuilder.MergeAttribute(&quot;href&quot;, &quot;#&quot;);                         builder.AppendLine(&quot;&lt;li class=\\&quot;active\\&quot;&gt;&quot; + subBuilder.ToString() + &quot;&lt;\/li&gt;&quot;);                     }                     else                     {                         subBuilder.MergeAttribute(&quot;href&quot;, pageUrl.Invoke(i));                         builder.AppendLine(&quot;&lt;li&gt;&quot; + subBuilder.ToString() + &quot;&lt;\/li&gt;&quot;);                     }                 }                 else if ((i == 4) && (currentPage &gt; 5))                 {                     \/\/\u0422\u0440\u043e\u0435\u0442\u043e\u0447\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0435                     builder.AppendLine(&quot;&lt;li class=\\&quot;disabled\\&quot;&gt; &lt;a href=\\&quot;#\\&quot;&gt;...&lt;\/a&gt; &lt;\/li&gt;&quot;);                 }                 else if ((i == (totalPages - 3)) && (currentPage &lt; (totalPages - 4)))                 {                     \/\/\u0422\u0440\u043e\u0435\u0442\u043e\u0447\u0438\u0435 \u0432\u0442\u043e\u0440\u043e\u0435                     builder.AppendLine(&quot;&lt;li class=\\&quot;disabled\\&quot;&gt; &lt;a href=\\&quot;#\\&quot;&gt;...&lt;\/a&gt; &lt;\/li&gt;&quot;);                 }             }             \/\/Next             var nextBuilder = new TagBuilder(&quot;a&quot;);             nextBuilder.InnerHtml = &quot;&raquo;&quot;;             if (currentPage == totalPages)             {                 nextBuilder.MergeAttribute(&quot;href&quot;, &quot;#&quot;);                 builder.AppendLine(&quot;&lt;li class=\\&quot;active\\&quot;&gt;&quot; + nextBuilder.ToString() + &quot;&lt;\/li&gt;&quot;);             }             else             {                 nextBuilder.MergeAttribute(&quot;href&quot;, pageUrl.Invoke(currentPage + 1));                 builder.AppendLine(&quot;&lt;li&gt;&quot; + nextBuilder.ToString() + &quot;&lt;\/li&gt;&quot;);             }             return new MvcHtmlString(&quot;&lt;ul&gt;&quot; + builder.ToString() + &quot;&lt;\/ul&gt;&quot;);         } <\/code><\/pre>\n<p>  \u2003<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c namespace LessonProject.Helper \u0432 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u043e View. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:  <\/p>\n<ul>\n<li>\u0412 \u0441\u0430\u043c\u043e\u043c View<br \/> \n<pre><code class=\"html\">@using LessonProject.Helper; <\/code><\/pre>\n<p>  <\/li>\n<li>\u0412 Web.config (\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f)<br \/> \n<pre><code class=\"xml\">&lt;configSections&gt; \u2026 &lt;sectionGroup name=&quot;system.web.webPages.razor&quot; type=&quot;System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;&gt;       &lt;section name=&quot;host&quot; type=&quot;System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot; requirePermission=&quot;false&quot; \/&gt;       &lt;section name=&quot;pages&quot; type=&quot;System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot; requirePermission=&quot;false&quot; \/&gt;     &lt;\/sectionGroup&gt; &lt;\/configSections&gt; +  &lt;system.web.webPages.razor&gt;     &lt;pages pageBaseType=&quot;System.Web.Mvc.WebViewPage&quot;&gt;       &lt;namespaces&gt;         &lt;add namespace=&quot;LessonProject.Helper&quot; \/&gt;       &lt;\/namespaces&gt;     &lt;\/pages&gt; &lt;\/system.web.webPages.razor&gt; <\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440 \u0432\u043e View:   <\/p>\n<pre><code class=\"html\">   &lt;div class=&quot;pagination&quot;&gt;         @Html.PageLinks(Model.PageNo, Model.CountPage, x =&gt; Url.Action(&quot;Index&quot;, new {page = x}))     &lt;\/div&gt; <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <br \/>  <code>x =&gt; Url.Action(&quot;Index&quot;, new {page = x})<\/code><br \/>  \u042d\u0442\u043e \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0410 Url.Action() \u2013 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \/User\/Index \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c page = x.<br \/>  \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c (\u0443\u043c\u0435\u043d\u044c\u0448\u0438\u043b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e 5, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446):<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/22e\/d2a\/a25\/22ed2aa2511ee301fd930e055927b248.jpg\"\/><\/p>\n<h5>SearchEngine<\/h5>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u0430. \u041f\u043e\u0438\u0441\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043f\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044e \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2013 searchString.   <\/p>\n<pre><code class=\"cs\">public ActionResult Index(int page = 1, string searchString = null)         {             if (!string.IsNullOrWhiteSpace(searchString))             {                 \/\/\u0442\u0443\u0442 \u041f\u043e\u0438\u0441\u043a                  return View(data);             }             else             {                 var data = new PageableData&lt;User&gt;(Repository.Users, page, 5);                 return View(data);             }         } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>SearchEngine<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<code> IQueryable&lt;User&gt;<\/code>, \u0438 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 (\/Global\/SearchEngine.cs):<br \/>  \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e \u043e\u0447\u0438\u0441\u0442\u043a\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0442\u0435\u0433\u043e\u0432 \u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u0442\u0438\u043f\u0430 [,], {,}, (,):  <\/p>\n<pre><code class=\"cs\">  \/\/\/ &lt;summary&gt;         \/\/\/ The regex strip html.         \/\/\/ &lt;\/summary&gt;         private static readonly Regex RegexStripHtml = new Regex(&quot;&lt;[^&gt;]*&gt;&quot;, RegexOptions.Compiled);           private static string StripHtml(string html)         {             return string.IsNullOrWhiteSpace(html) ? string.Empty :                  RegexStripHtml.Replace(html, string.Empty).Trim();         }          private static string CleanContent(string content, bool removeHtml)         {             if (removeHtml)             {                 content = StripHtml(content);             }              content =                 content.Replace(&quot;\\\\&quot;, string.Empty).                 Replace(&quot;|&quot;, string.Empty).                 Replace(&quot;(&quot;, string.Empty).                 Replace(&quot;)&quot;, string.Empty).                 Replace(&quot;[&quot;, string.Empty).                 Replace(&quot;]&quot;, string.Empty).                 Replace(&quot;*&quot;, string.Empty).                 Replace(&quot;?&quot;, string.Empty).                 Replace(&quot;}&quot;, string.Empty).                 Replace(&quot;{&quot;, string.Empty).                 Replace(&quot;^&quot;, string.Empty).                 Replace(&quot;+&quot;, string.Empty);              var words = content.Split(new[] { ' ', '\\n', '\\r' }, StringSplitOptions.RemoveEmptyEntries);             var sb = new StringBuilder();             foreach (var word in                 words.Select(t =&gt; t.ToLowerInvariant().Trim()).Where(word =&gt; word.Length &gt; 1))             {                 sb.AppendFormat(&quot;{0} &quot;, word);             }              return sb.ToString();         } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a:  <\/p>\n<pre><code class=\"cs\">public static IEnumerable&lt;User&gt; Search(string searchString, IQueryable&lt;User&gt; source)         {             var term = CleanContent(searchString.ToLowerInvariant().Trim(), false);             var terms = term.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);             var regex = string.Format(CultureInfo.InvariantCulture, &quot;({0})&quot;, string.Join(&quot;|&quot;, terms));              foreach (var entry in source)             {                 var rank = 0;                                 if (!string.IsNullOrWhiteSpace(entry.Email))                 {                     rank += Regex.Matches(entry.Email.ToLowerInvariant(), regex).Count;                 }                 if (rank &gt; 0)                 {                     yield return entry;                 }             }         } <\/code><\/pre>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0421\u043e\u0437\u0434\u0430\u0435\u043c regex \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0438\u0449\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u043e\u043b\u0435 Email \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. <\/p>\n<p>  \u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:  <\/p>\n<ul>\n<li>\u041f\u0440\u0438 \u0432\u0432\u043e\u0434\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u043e\u0438\u0441\u043a\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u00abcher [2]\u00bb, \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u00abcher 2\u00bb. <\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0435\u043c regex = (cher|2).<\/li>\n<li>\u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0447\u0435\u0440\u0435\u0437<code>IQueryable&lt;User&gt;<\/code> <\/li>\n<li>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435, \u0442\u043e \u0432\u044b\u043d\u043e\u0441\u0438\u043c \u0435\u0433\u043e \u0432 IEnumerable \u2014 yield return entry <\/li>\n<\/ul>\n<p>  \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c Action (\/Areas\/Default\/Controller\/UserController.cs):  <\/p>\n<pre><code class=\"html\">public ActionResult Index(int page = 1, string searchString = null)         {      ViewBag.Search = searchString;             if (!string.IsNullOrWhiteSpace(searchString))             {                 var list = SearchEngine.Search(searchString, Repository.Users).AsQueryable();                 var data = new PageableData&lt;User&gt;(list, page, 5);                 return View(data);             }             else             {                 var data = new PageableData&lt;User&gt;(Repository.Users, page, 5);                 return View(data);             }         } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u043e View:  <\/p>\n<pre><code class=\"html\">@{     ViewBag.Title = &quot;Users&quot;;     Layout = &quot;~\/Areas\/Default\/Views\/Shared\/_Layout.cshtml&quot;;     var searchString = (string)ViewBag.Search; }  &lt;h2&gt;Users&lt;\/h2&gt;  @using (Html.BeginForm(&quot;Index&quot;, &quot;User&quot;, FormMethod.Post, new { @class = &quot;form-search&quot; })) {     @Html.TextBox(&quot;searchString&quot;, searchString ?? &quot;&quot;, new { @class = &quot;input-medium search-query&quot; })     &lt;button type=&quot;submit&quot; class=&quot;btn&quot;&gt;\u041f\u043e\u0438\u0441\u043a&lt;\/button&gt;  }  <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 <code>ViewBag<\/code>, \u044d\u0442\u043e dynamic \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430:<br \/>  <code>@Html.PageLinks(Model.PageNo, Model.CountPage, x =&gt; Url.Action(&quot;Index&quot;, new {page = x, searchString}))<\/code><\/p>\n<h5>Extension<\/h5>\n<p>  \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0438\u043b\u0438 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439, \u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u044d\u0442\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 LessonProject.Tools class WebExtensions:   <\/p>\n<pre><code class=\"cs\">public static class WebExtensions    {    } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0432 reference LessonProject.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/ee5\/3d1\/52b\/ee53d152bd2c7e3749d694e9cad1a73e.jpg\"\/><\/p>\n<p>  \u041c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u043c \\r\\n, \u0438 \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u044d\u0442\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e NlToBr(). \u0421\u043e\u0437\u0434\u0430\u0435\u043c:  <\/p>\n<pre><code class=\"cs\">public static MvcHtmlString NlToBr(this string source) {             if (string.IsNullOrWhiteSpace(source))             {                 return new MvcHtmlString(string.Empty);             }             return new MvcHtmlString(source.Replace(Environment.NewLine, &quot;&lt;br \/&gt;&quot;)); } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 Web.config:   <\/p>\n<pre><code class=\"xml\"> &lt;add namespace=&quot;LessonProject.Tools&quot; \/&gt; <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:  <\/p>\n<pre><code class=\"html\">@Model.Description.NlToBr() <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Teaser, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0440\u0435\u0437\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438 \u0441\u0442\u0430\u0432\u0438\u0442 \u00ab\u2026\u00bb \u043f\u043e\u0441\u043b\u0435, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0434\u043b\u0438\u043d\u043d\u0435\u0435.   <\/p>\n<pre><code class=\"cs\">public static string Teaser(this string content, int length, string more = &quot;...&quot;)         {             if (string.IsNullOrWhiteSpace(content))             {                 return string.Empty;             }              if (content.Length &lt; length)             {                 return content;             }              return content.Substring(0, length) + more;         } <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e:  <\/p>\n<pre><code class=\"html\">@Model.Description.Teaser(120, \u201c&gt;&gt;&gt;\u201d) <\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u0430\u043c \u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e \u0438\u0437 \u0441\u043b\u043e\u0432 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0434\u043b\u044f 1, 2 \u0438\u043b\u0438 5. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 1 \u0433\u043e\u0434, 2 \u0433\u043e\u0434\u0430, 5 \u043b\u0435\u0442:   <\/p>\n<pre><code class=\"cs\"> public static string CountWord(this int count, string first, string second, string five)         {             if (count % 10 == 1 && (int)(count \/ 10) != 1)             {                 return first;             }             if (count % 10 &gt; 1 && count % 10 &lt; 5 && ((int)(count \/ 10) % 10) != 1)             {                 return second;             }             return five;         } <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"html\">@year @year.CountWord(\u201c\u0433\u043e\u0434\u201d, \u201c\u0433\u043e\u0434\u0430\u201d, \u201c\u043b\u0435\u0442\u201d) <\/code><\/pre>\n<p>  \u2003  <\/p>\n<h5>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/h5>\n<p>  \u042f \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b <a href=\"http:\/\/habrahabr.ru\/post\/88766\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u041d\u043e \u0442\u043e \u0431\u044b\u043b asp.net mvc \u043f\u0435\u0440\u0432\u044b\u0439, \u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435.<br \/>  \u0417\u043d\u0430\u0447\u0438\u0442, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c. \u041c\u044b \u043d\u0430 post-action \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:  <\/p>\n<pre><code class=\"cs\">  public class Ownership     {         public string Name { get; set; }          public int Price { get; set; }     }     public class Customer     {         public int ID { get; set; }           public string Name { get; set; }          public Dictionary&lt;string,Ownership&gt; Ownerships { get; set; }     } <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 List \u0432\u043c\u0435\u0441\u0442\u043e Dictionary, \u043d\u043e, \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. <\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:  <\/p>\n<pre><code class=\"cs\">public class CustomerController : DefaultController     {         [HttpGet]         public ActionResult Edit(int id)         {             return View(new Customer()             {                   Ownerships = new Dictionary&lt;string, Ownership&gt;()             });         }         [HttpPost]         public ActionResult Edit(Customer customer)         {             if (ModelState.IsValid)             {             }             return View(customer);         }     } <\/code><\/pre>\n<p>  \u0412 \u0411\u0414 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c View:  <\/p>\n<pre><code class=\"html\">@model LessonProject.Models.Info.Customer  @{     ViewBag.Title = &quot;Edit&quot;;     Layout = &quot;~\/Areas\/Default\/Views\/Shared\/_Layout.cshtml&quot;; } @section scripts {     @Scripts.Render(&quot;\/Scripts\/default\/customer-edit.js&quot;) }   &lt;h2&gt;Edit&lt;\/h2&gt;  @using (Html.BeginForm(&quot;Edit&quot;, &quot;Customer&quot;, FormMethod.Post, new { @class = &quot;form-horizontal&quot; })) {     &lt;fieldset&gt;         @Html.Hidden(&quot;ID&quot;, Model.ID)         &lt;div class=&quot;control-group&quot;&gt;             &lt;label class=&quot;control-label&quot; for=&quot;Email&quot;&gt;                 Name&lt;\/label&gt;             &lt;div class=&quot;controls&quot;&gt;                 @Html.TextBox(&quot;Name&quot;, Model.Name, new { @class = &quot;input-xlarge&quot; })                 @Html.ValidationMessage(&quot;Name&quot;)             &lt;\/div&gt;         &lt;\/div&gt;         &lt;div id=&quot;OwnershipListWrapper&quot;&gt;             &lt;div class=&quot;btn&quot; id=&quot;AddOwnership&quot;&gt;\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c&lt;\/div&gt;              @foreach (var keyValuePair in Model.Ownerships)             {                 @Html.Partial(&quot;OwnershipItem&quot;, keyValuePair)             }         &lt;\/div&gt;          &lt;div class=&quot;form-actions&quot;&gt;             &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;                 \u041e\u043a&lt;\/button&gt;         &lt;\/div&gt;     &lt;\/fieldset&gt; }  <\/code><\/pre>\n<p>  <code>KeyValuePair <\/code>\u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u0432 <code>PartialView <\/code>(\/Areas\/Default\/Views\/Customer\/OwnershipItem.cshtml):  <\/p>\n<pre><code class=\"html\">@model KeyValuePair&lt;string, LessonProject.Models.Info.Ownership&gt;  &lt;div class=&quot;OwnershipWrapper&quot;&gt;     &lt;div class=&quot;btn remove-line&quot;&gt;\u0423\u0434\u0430\u043b\u0438\u0442\u044c&lt;\/div&gt;      &lt;div class=&quot;control-group&quot;&gt;         &lt;label class=&quot;control-label&quot;&gt;             \u0418\u043c\u044f         &lt;\/label&gt;         &lt;div class=&quot;controls&quot;&gt;             @Html.TextBox(&quot;Ownerships[&quot; + Model.Key + &quot;].Name&quot;, Model.Value.Name, new { @class = &quot;input-xlarge&quot; })             @Html.ValidationMessage(&quot;Ownerships[&quot; + Model.Key +  &quot;].Name&quot;)         &lt;\/div&gt;     &lt;\/div&gt;     &lt;div class=&quot;control-group&quot;&gt;         &lt;label class=&quot;control-label&quot;&gt;             \u0426\u0435\u043d\u0430         &lt;\/label&gt;         &lt;div class=&quot;controls&quot;&gt;             @Html.TextBox(&quot;Ownerships[&quot; + Model.Key +  &quot;].Price&quot;, Model.Value.Price, new { @class = &quot;input-xlarge&quot; })             @Html.ValidationMessage(&quot;Ownerships[&quot; + Model.Key +  &quot;].Price&quot;)         &lt;\/div&gt;     &lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  Js-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043d\u043e\u043f\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f (\/Scripts\/default\/customer-edit.js):  <\/p>\n<pre><code class=\"javascript\">function CustomerEdit() {     _this = this;      this.ajaxAddOwnership = &quot;\/Customer\/AddOwnership&quot;;      this.init = function () {         $(&quot;#AddOwnership&quot;).click(function () {             $.ajax({                 type: &quot;GET&quot;,                 url: _this.ajaxAddOwnership,                 success: function (data) {                     $(&quot;#OwnershipListWrapper&quot;).append(data);                 }             })         });          $(document).on(&quot;click&quot;, &quot;.remove-line&quot;, function () {             $(this).closest(&quot;.OwnershipWrapper&quot;).remove();         });     } }  var customerEdit = null; $().ready(function () {     customerEdit = new CustomerEdit();     customerEdit.init(); }); <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u00ab\u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c\u00bb, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u0447\u0430\u0441\u0442\u044c \u0443\u0436\u0435 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a \u0441\u043f\u0438\u0441\u043a\u0443. \u041f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043f\u043e \u043a\u043b\u0438\u043a\u0443, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u0438\u043c \u0440\u044f\u0434 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0430\u0439\u0434\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 OwnershipWrapper. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0434\u043b\u044f remove-line. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0442\u043e\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u043a\u043b\u0438\u043a.<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 CustomerController, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 View OwnershipItem.cshtml:  <\/p>\n<pre><code class=\"cs\">public ActionResult AddOwnership()         {             return View(&quot;OwnershipItem&quot;, new KeyValuePair&lt;string, Ownership&gt;(                 Guid.NewGuid().ToString(&quot;N&quot;),                  new Ownership()));         } <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/b4c\/6fc\/92b\/b4c6fc92b7ec29ecc9d3958f9206dcec.jpg\"\/><\/p>\n<h5>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f <\/h5>\n<p>  \u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0445\u043e\u0436\u0438, \u043d\u043e \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u0420\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u0445\u043e\u0434\u0430 \u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 404 (\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430).<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0434\u043c\u0438\u043d\u043a\u0435, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043d\u0435 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d\u044b, \u0438\u043b\u0438 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d\u044b, \u043d\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u043c \u043f\u0440\u0430\u0432 \u043d\u0430 \u044d\u0442\u043e, \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u0438\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u0432 Web.config \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 authentication:  <\/p>\n<pre><code class=\"xml\">&lt;authentication mode=&quot;Forms&quot;&gt;       &lt;forms loginUrl=&quot;~\/Login&quot; timeout=&quot;2880&quot; \/&gt;     &lt;\/authentication&gt; <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0442.\u0435. \u043f\u043e \u0434\u0430\u043d\u043d\u044b\u043c \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438 action-\u043c\u0435\u0442\u043e\u0434, \u0442\u043e \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 customErrors \u0432 Web.config:  <\/p>\n<pre><code class=\"xml\">&lt;customErrors mode=&quot;On&quot;  redirectMode=&quot;ResponseRedirect&quot; defaultRedirect=&quot;~\/Error&quot;&gt;       &lt;error statusCode=&quot;403&quot; redirect=&quot;~\/Error&quot; \/&gt;       &lt;error statusCode=&quot;404&quot; redirect=&quot;~\/NotFoundPage&quot; \/&gt;     &lt;\/customErrors&gt;  <\/code><\/pre>\n<p>  \u0422\u043e \u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u0430 \u0431\u043e\u0435\u0432\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u00ab\u0436\u0435\u043b\u0442\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u0441\u043c\u0435\u0440\u0442\u0438\u00bb, \u0433\u0434\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430, \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 404 \u0438\u043b\u0438 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u0445\u043e\u0434\u0430, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. <br \/>  \u042d\u0442\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0440\u043e\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430, \u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0437\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0443\u0436\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u0435\u043c\u0443 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0442\u043a\u0430\u0437\u0430\u043d\u043e. <br \/>  \u0418\u043b\u0438 \u0432\u0442\u043e\u0440\u043e\u0439, \u0438 \u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e \u0431\u0438\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 NotFoundPage.<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 BaseController (\/Controllers\/BaseController.cs):   <\/p>\n<pre><code class=\"cs\">protected static string ErrorPage = &quot;~\/Error&quot;;         protected static string NotFoundPage = &quot;~\/NotFoundPage&quot;;          protected static string LoginPage = &quot;~\/Login&quot;;          public RedirectResult RedirectToNotFoundPage         {             get             {                 return Redirect(NotFoundPage);             }         }          public RedirectResult RedirectToLoginPage         {             get             {                 return Redirect(LoginPage);             }         }  protected override void OnException(ExceptionContext filterContext)         {             base.OnException(filterContext);              filterContext.Result = Redirect(ErrorPage);         } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 RedirectToNotFoundPage \u0438 RedirectToLoginPage UserController (\/Areas\/Default\/Controllers\/UserController.cs) \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\"> [Authorize]         public ActionResult Edit(int id)         {             var user = Repository.Users.FirstOrDefault(p =&gt; p.ID == id);             if (user != null)             {                 if (CurrentUser.InRoles(&quot;admin&quot;) || CurrentUser.ID == id)                 {                     \/\/\u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435                     return View(user);                 }                 return RedirectToLoginPage;             }             return RedirectToNotFoundPage;         } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043d\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u043a\u043e\u0442\u043e\u0433\u043e \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0430.<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 404-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 <code>BaseController<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435\u043d\u0430\u0440\u043e\u043a\u043e\u043c \u043d\u0435 \u0437\u0430\u0446\u0435\u043f\u0438\u0442\u044c \u0435\u0449\u0435 \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0448\u0438\u0431\u043a\u0443. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0443\u0442\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 (\/Areas\/Default\/DefaultAreaRegistration.cs):  <\/p>\n<pre><code class=\"cs\">context.MapRoute(                 null,                 url: &quot;Error&quot;,                 defaults: new { controller = &quot;Error&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional },                 namespaces: new[] { &quot;LessonProject.Areas.Default.Controllers&quot; }             );              context.MapRoute(                 null,                 url: &quot;NotFoundPage&quot;,                 defaults: new { controller = &quot;Error&quot;, action = &quot;NotFoundPage&quot;, id = UrlParameter.Optional },                 namespaces: new[] { &quot;LessonProject.Areas.Default.Controllers&quot; }             ); <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 (\/Areas\/Default\/Controllers\/ErrorController.cs):  <\/p>\n<pre><code class=\"cs\">public class ErrorController : Controller     {         public ActionResult Index()         {             Response.StatusCode = (int)HttpStatusCode.InternalServerError;             return View();          }          public ActionResult NotFoundPage()         {             Response.StatusCode = (int)HttpStatusCode.NotFound;             return View();          }     } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 View (\/Areas\/Default\/Views\/Error\/Index.cshtml):  <\/p>\n<pre><code class=\"html\">@{     Layout = null; }  &lt;!DOCTYPE html&gt;  &lt;html&gt; &lt;head&gt;     &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; \/&gt;     &lt;title&gt;Index&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt;     &lt;div&gt;         \u041e\u0448\u0438\u0431\u043a\u0430 &lt;br \/&gt;         &lt;a href=&quot;\/&quot;&gt;\u0412\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e&lt;\/a&gt;     &lt;\/div&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 404 (\/Areas\/Default\/Views\/Error\/NotFoundPage.cshtml).<\/p>\n<h5>\u0414\u0440\u0443\u0433\u0438\u0435 ActionResult<\/h5>\n<p>  ActionResult \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c View. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b:  <\/p>\n<ul>\n<li><b>Content(result)<\/b> \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u0432 http-\u043e\u0442\u0432\u0435\u0442\u0435<\/li>\n<li><b>JsonResult(object)<\/b> \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 json (\u0434\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c)<\/li>\n<li><b>FileContentResult()<\/b> \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441 \u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430. (\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u2014 \u043c\u0441\u0434\u043d)<\/li>\n<li><b>FilePathResult()<\/b> \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0430\u0439\u043b, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438<\/li>\n<li><b>FileStreamResult()<\/b> \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432 \u0444\u0430\u0439\u043b\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a<\/li>\n<li><b>RedirectResult()<\/b> \u2013 \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/li>\n<li><b>RedirectToRouteResult()<\/b> \u2013 \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043f\u043e \u043d\u043e\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438<\/li>\n<\/ul>\n<h5>RssActionResult<\/h5>\n<p>  RSS \u2013 \u044d\u0442\u043e XML \u0444\u043e\u0440\u043c\u0430\u0442, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043b\u0435\u043d\u0442 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439, \u0441\u0442\u0430\u0442\u0435\u0439, \u0431\u043b\u043e\u0433\u043e\u0432. \u0423 \u043d\u0430\u0441 \u043f\u043e\u043a\u0430 \u043d\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c RssActionResult. \u0412 <code>System.ServiceModel.Syndication<\/code> \u2013 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 RSS. \u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b SyndicationFeed \u0438 SyndicationItem. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c System.ServiceModel \u0432 reference, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 (\/Areas\/Default\/Controllers\/FeedController.cs):<\/p>\n<pre><code class=\"cs\">public class FeedController : DefaultController     {         public ActionResult Index()         {             var host = Request.Url;             var feed =                new SyndicationFeed(&quot;Site RSS&quot;,                                    &quot;&quot;,                                    new Uri(host.AbsoluteUri + &quot;\/Feed&quot;));              var items = new List&lt;SyndicationItem&gt;();              var item = new SyndicationItem(                &quot;Title&quot;,                &quot;content&quot;,                new Uri(&quot;http:\/\/&quot; + host + &quot;\/some-link-url&quot;),                &quot;Title&quot;,                DateTime.Now                );             items.Add(item);             feed.Items = items;              return View();         }      } <\/code><\/pre>\n<p>  \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c RssActionResult (\/Global\/RssActionResult.cs):  <\/p>\n<pre><code class=\"cs\">public class RssActionResult : ActionResult     {         public SyndicationFeed Feed { get; set; }          public override void ExecuteResult(ControllerContext context)         {             context.HttpContext.Response.ContentType = &quot;application\/rss+xml&quot;;              var rssFormatter = new Rss20FeedFormatter(Feed);             using (var writer = XmlWriter.Create(context.HttpContext.Response.Output))             {                 rssFormatter.WriteTo(writer);             }         }     } <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Feed, \u043a\u0443\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Feed. \u0421\u0430\u043c ActionResult \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 ExecuteResult(). \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Rss20FeedFormatted \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 xml \u0432 Response.Output. Response.Output \u2013 \u044d\u0442\u043e stream, \u043a\u0443\u0434\u0430 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u043e\u043d\u0438\u043c\u0430\u043b, \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c, \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0432 <code>Response.ContentType = \u201capplication\/rss+xml\u201d.<\/code><br \/>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0448 RssActionResult (\/Areas\/Default\/Controllers\/FeedController.cs):   <\/p>\n<pre><code class=\"cs\">\u2026 return new RssActionResult {Feed = feed }; <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d06\/31b\/ab1\/d0631bab1fa4ed1c5a8da93f08532c6e.jpg\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/rss-subscription-extensio\/nlbjncdgjeocebhnmkbbbdekmmmcbfjd\">RSS Subscription Extension (by Google)<\/a>, \u0442\u043e \u043d\u0430\u0448 RSS-\u043a\u0430\u043d\u0430\u043b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u0441\u044f \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0438 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f.:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/e05\/f22\/8a8\/e05f228a80284eb044af6a5c7e3410d3.jpg\"\/><\/p>\n<p>  \u041c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c Sitemap \u0432\u044b\u0432\u043e\u0434. \u0412\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b <a href=\"http:\/\/www.sitemaps.org\/protocol.html\">http:\/\/www.sitemaps.org\/protocol.html<\/a>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442.<\/p>\n<p>  \u0412\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/bitbucket.org\/chernikov\/lessons\">https:\/\/bitbucket.org\/chernikov\/lessons<\/a>    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/176063\/\"> http:\/\/habrahabr.ru\/post\/176063\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430<\/b>. \u041d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 html, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Razor. Helper\u044b. PageableData. \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u044b. RedirectToLogin, RedirectToNotFoundPage. \u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043e\u0448\u0438\u0431\u043a\u0438. RssActionResult.<\/p>\n<h5>\u041e\u0441\u043d\u043e\u0432\u0430<\/h5>\n<p>  \u0418\u0442\u0430\u043a, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0447\u0430\u0441\u0442\u044c View.<br \/>  \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0432\u0441\u0435 action-\u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0442\u0438\u043f ActionResult. \u0418 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<br \/>  <code>return View(modelData);<\/code><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-176063","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176063"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176063\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}