如何在mvc中使用next和prev锚链接显示详细信息 [英] how to show Details using next and prev anchor link in mvc

查看:122
本文介绍了如何在mvc中使用next和prev锚链接显示详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是mvc的新手,并且想知道如何在用户单击下一个时使用上一个和下一个锚标记显示记录的详细信息,然后显示ID 2的详细信息,然后再次单击下一个,然后显示3的详细信息被显示.我该怎么做才能实现此功能.到目前为止,我已经尝试过了.请帮忙.

i am new to mvc and want to know how to show a details of a record using previous and next anchor tag when user click on next then details of id 2 should be displayed , and again click on next then details of 3 should be displayed. how can i do that stuck here to implement this functionality. what i have tried so far please help.

view 
@model Webapp.Models.Person

<div class="navi-but">
                            <a href="#"><span class="previous">Previous</span></a>
                        <a href="#"><span style="padding-right:7px">Next</span><span class="next"></span></a>
</div>
<div>

    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.PersonName)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.PersonName)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Description)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Description)
        </dd>


    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.PersonId }) |
    @Html.ActionLink("Back to List", "Index")
</p>


Controller
public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person personmodel = db.Persons.Find(id);
            if (personmodel == null)
            {
                return HttpNotFound();
            }
            return View(personmodel);
        }

推荐答案

添加ID来标记btn next和btnprevious并进行如下的ajax调用:

add ids to tag btn next and btnprevious and make ajax calls as below:

$("#btnNext").click(function () {
    $.ajax({
       url: 'Category/Next',
        data: { personId:cureentid  },
       success: function (response) {
        $("body").html(response);
    }
  });
 });


$("#btnPrevious").click(function () {
   $.ajax({
      url: 'Category/Previous',
      data: { personId:cureentid },
      success: function (response) {
          $("body").html(response);
      }
    });
});

public ActionResult Next(int personId )
{
   personId++;
   redirecttoactionmethod(persodetails(personId ))

}

public ActionResult Previous(int personId )

{

      personId--;
   redirecttoactionmethod(persodetails(personId ))

}

这篇关于如何在mvc中使用next和prev锚链接显示详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆