我正在MVC中做一个项目,我想生成一部分页面并更改URL。
以下是代码的一部分:
<div id="body">
<div class="container-fluid">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container" style="padding-bottom: 30px">
<div class="row">
<div class="col-md-12">
<h2>Indexação de documentos clínicos</h2>
</div>
<div class="col-md-12">
<div class="input-group">
<input type="text" class="form-control" placeholder="Procurar por..." id="contId" value="@ViewBag.searchModel.SearchTerm"/>
<span class="input-group-btn">
<button id="searchBtn" class="btn btn-default" type="button" value="Search" onclick="find();">Procurar</button>
</span>
</div>
</div>
</div>
</div>
</nav>
<div class="container" style="padding-top: 150px;">
<div class="row">
<div class="col-md-12">
<div class="list-group" id="contribution">@Html.Partial("ResultsPartial")</div>
</div>
</div>
<div class="row">
<div id="pagination" class="col-md-12">
@if (ViewBag.searchModel.TotalResults != 0 && ViewBag.searchModel.NumberOfPages>1)
{
<ul class="pagination">
@{
for (int i = 1; i <= ViewBag.searchModel.NumberOfPages; i++)
{
<li><a href="#" id="@i" onclick="changePage(@i);">@i</a></li>
}
}
</ul>
}
</div>
</div>
</div>
</div>
这是与search view
相关的HTML。当我搜索某些内容时,我只想重新加载显示结果和页码(链接)的页面部分,如果需要的话。不过,我需要使用页面和搜索关键字保存URL。
有没有办法在不重新加载所有页面的情况下执行此操作?
这是控制器(暂时重新加载所有页面):
public ActionResult Search(string id, int page)
{
searchModel.SearchTerm = id;
searchModel.Page = page - 1;
List<Dictionary<string, string>> res = new ContributionsController().GetContributions(searchModel.SearchTerm, searchModel.StartPage, searchModel.Rows);
searchModel.Results = res;
if (res.Count==0)
{
searchModel.Reset();
return View("Index");
}
searchModel.TotalResults = Convert.ToInt32(res[0]["total_num"]);
ViewBag.searchModel = searchModel;
return View("Index");
}
谢谢=)