snipt

Ctrl+h for KB shortcuts

C#

petaPoco MvcContrib

1
2
3
4
5
6
public ActionResult Index(int? page)
{
    var pagedModel = Db.Page<SomeModel>(page ?? 1, 10, "").AsPagination();

    return View(pagedModel);
}
https://snipt.net/embed/d978c05c0cb534c8a742d4d44ec1ba33/
/raw/d978c05c0cb534c8a742d4d44ec1ba33/
d978c05c0cb534c8a742d4d44ec1ba33
csharp
C#
6
2019-08-24T17:08:55
True
False
False
/api/public/snipt/34555/
petapoco-mvccontrib-1
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">public</span> <span class="n">ActionResult</span> <span class="nf">Index</span><span class="p">(</span><span class="kt">int?</span> <span class="n">page</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="kt">var</span> <span class="n">pagedModel</span> <span class="p">=</span> <span class="n">Db</span><span class="p">.</span><span class="n">Page</span><span class="p">&lt;</span><span class="n">SomeModel</span><span class="p">&gt;(</span><span class="n">page</span> <span class="p">??</span> <span class="m">1</span><span class="p">,</span> <span class="m">10</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">).</span><span class="n">AsPagination</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="nf">View</span><span class="p">(</span><span class="n">pagedModel</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
mvccontrib, petapoco

C#

petaPoco mvcContrib

1
2
3
4
5
6
7
8
public static IPagination<T> AsPagination<T>(this Page<T> page)
{
    return new CustomPagination<T>(
        page.Items,
        (int)page.CurrentPage,
        (int)page.ItemsPerPage,
        (int)page.TotalItems);
}
https://snipt.net/embed/cbdc4b3bbf8c785acc4fa93a5b2590e2/
/raw/cbdc4b3bbf8c785acc4fa93a5b2590e2/
cbdc4b3bbf8c785acc4fa93a5b2590e2
csharp
C#
8
2019-08-24T05:19:24
True
False
False
/api/public/snipt/34553/
petapoco-mvccontrib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">public</span> <span class="k">static</span> <span class="n">IPagination</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;</span> <span class="n">AsPagination</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;(</span><span class="k">this</span> <span class="n">Page</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;</span> <span class="n">page</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="k">new</span> <span class="n">CustomPagination</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;(</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">page</span><span class="p">.</span><span class="n">Items</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">page</span><span class="p">.</span><span class="n">CurrentPage</span><span class="p">,</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">page</span><span class="p">.</span><span class="n">ItemsPerPage</span><span class="p">,</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">page</span><span class="p">.</span><span class="n">TotalItems</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
mvccontrib, petapoco