I have 2 seperate views and each of them call upon a controller that uploads a file. They both work okay the 1st time I use them, however for some unkown reason when i switch views the controllers from each view are swapped!! I double checked and i call each controller correctly. So i have no idea why the controllers are swapped between views!
Here is where I input the file:
<div class="options">
<input type="button" id="importexcel" name="importexcel" class="k-button" value="Select Excel File" />#*#T("Admin.Common.ImportFromExcel")" />*#
</div>
using(Html.BeginForm("GetFile", "Product", FormMethod.Post, new { EncType = "multipart/form-data" }))
{
<br />
}
<div id="importexcel-window" style="display:none;">
#using (Html.BeginForm("GetFile", "Product", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
#Html.AntiForgeryToken()
#Html.HiddenFor(x => x.Id)
<table style="text-align:left;">
<tr>
<td colspan="2">
<em>#T("Admin.Catalog.Products.List.ImportFromExcelTip")</em>
</td>
</tr>
<tr>
<td>
#T("Admin.Common.ExcelFile"):
</td>
<td>
<input type="file" id="importexcelfile" name="importexcelfile" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="k-button" value="#T("Admin.Common.ImportFromExcel")" />
</td>
</tr>
</table>
}
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#importexcel").click(function (e) {
e.preventDefault();
var window = $("#importexcel-window");
if (!window.data("kendoWindow")) {
window.kendoWindow({
modal: true,
width: "400px",
title: "#T("Admin.Common.ImportFromExcel")",
actions: ["Close"]
});
}
window.data('kendoWindow').center().open();
});
});
</script>
And here is the respective controller:
[HttpPost]
public ActionResult GetFile(int Id, HttpPostedFileBase importexcelfile)
{
/* read data from file */
var file = System.Web.HttpContext.Current.Request.Files[0];
FileChoosen = true;
FilePath = importexcelfile;
if (file.ContentLength > 0)
{
/* load and show data */
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Administration/Content/Excel/"), fileName);
file.SaveAs(path);
}
return RedirectToAction("Edit", new { id = Id });
}
As mentioned above i have another input controller alike to this one in a different view with a different name: (notice its exactly alike the one on top but with a different name "GetXML" and "importXMLfile"
Here is the controller
[HttpPost]
public ActionResult GetXML(int Id, HttpPostedFileBase importXMLfile)
{}
And here is where i input it:
<div id="importexcel-window" style="display:none;">
#using (Html.BeginForm("GetXML", "Product", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
#Html.AntiForgeryToken()
#Html.HiddenFor(x => x.Id)
<table style="text-align:left;">
<tr>
<td>
#T("Admin.Common.ExcelFile"):
</td>
<td>
<input type="file" id="importXMLfile" name="importXMLfile" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="k-button" value="#T("Admin.Common.ImportFromExcel")" />
</td>
</tr>
</table>
}
Related
I have created a project in which you can upload, download, delete, and preview files based (and displayed) on categories. How can I enable the user to create and link a new category within the site? I am very new to this and don't know how to. Here is my index page:
#model IEnumerable<Proiect2PracticaClona.Models.Files>
<center>
<h1>Suntem fericiti</h1>
<h2>Ca ne merge proiectu</h2>
<hr />
#if (User.IsInRole("Admin"))
{
<form methord="post" enctype="multipart/form-data" asp-controller="Home" asp-action="Index">
<input type="file" name="fifile" />
<div>Alegeti categoria de skill pentru care doriti sa uploadati</div>
<div>#Html.RadioButton("category", "incepator", "all")<label>Incepatori</label></div>
<div>#Html.RadioButton("category", "intermediar", "all")<label>Intermediari</label></div>
<div>#Html.RadioButton("category", "admin", "all")<label>Admini</label></div>
<input type="submit" value="Uploadati" />
<hr />
</form>}
<div>
File Name:<input id="search" onkeyup="search()" placeholder="cauta"/>
</div>
<table class="table">
<tr>
<th>Alegeti Categoria:</th>
<th class="active">#Html.ActionLink("Incepator", "Index", "Home", new { id = "incepator" })</th>
<th class="active">#Html.ActionLink("Intermediar", "Index", "Home", new { id = "intermediar" })</th>
<th class="active">#Html.ActionLink("Admin", "Index", "Home", new { id = "admin" })</th>
</tr>
<tr>
<th>File Name</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>#item.info</td>
<td>Download</td>
#if (User.IsInRole("Admin"))
{
<td>Delete</td>
}
</tr>
}
</table>
#section scripts
{
<script>
function search() {
$("tr").each(function (index, value) {
if (index > 0 && !$(this).find("td")[0].innerText.toLowerCase().includes($("#search").val().toLowerCase())) {
$(this).attr("hidden", true);
} else {
$(this).removeAttr("hidden");
}
console.log(value);
})
}
</script>
}
</center>
Controller Action:
[HttpPost]
public async Task<IActionResult> Index(IFormFile fifile, string category)
{
Category.category.Add(category);
var fisave = Path.Combine(_iweb.WebRootPath, "Uploads", fifile.FileName);
var stream = new FileStream(fisave, FileMode.Create);
await fifile.CopyToAsync(stream);
Files fileModel=new Files()
{
info = fifile.FileName,
category = category
};
_fileRepository.AddFile(fileModel);
stream.Close();
files = _fileRepository.GetFileList();
return RedirectToAction("Index",files);
}
Hi Everyone, I try to used the modal to avoid having multiple pages. but I got a problem, first, I click the view button and it will display to modal the right information; but when I click other view button instead the next data, it display the previous data.
second, after I select the view button and try to select the new shoes button (expectation must be display the new module in modal) it display the data of the previous item I select in view button:
Controller:
public ActionResult Index() //main page
{
var result = _Context.Shoeses.Include(x => x.Supply).ToList();
return View(result);
}
public ActionResult New() //create new product
{
var SupplierCategory = _Context.Suppliers.ToList();
var listOfSupplier = new ShoesViewModel
{
Supply = SupplierCategory
};
return PartialView(listOfSupplier);
}
public ActionResult Details(int id) //view selected data
{
Shoes productItem = new Shoes();
productItem = _Context.Shoeses.Find(id);
return PartialView("_Details", productItem);
}
View: Index
#model IEnumerable<ShoeInformation.Models.Shoes>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
<br />
<h2>Tindahan sa Bahay ni Tatang Benjamin</h2>
<br />
<br />
//my modal
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3 class="modal-title">Details</h3>
</div>
<div class="modal-body" id="modalBody">
Testing Only
</div>
</div>
</div>
</div>
//my modal
<p>#Html.ActionLink("New Shoes", "New", "Shoes", new { id="btn_Modal"}, new { #class = "btn btn-primary btn-lg",#data_toggle="modal" ,#data_target="#myModal"})</p>
<table class="table table-striped table-hover ">
<tr>
<th>Product ID
</th>
<th>Product Code
</th>
<th>Product Name
</th>
<th>Item Size
</th>
<th>Supplier
</th>
<th>Available Quantity
</th>
<th>Unit Price (Php)
</th>
<th>Action
</th>
</tr>
#foreach (var shoes in Model)
{
<tr class="success">
<td>
#shoes.Id
</td>
<td>
#shoes.ProductCode
</td>
<td>
#Html.ActionLink(#shoes.ProductName, "Edit", "Shoes", new { id=shoes.Id})
</td>
<td>
#shoes.ItemSize
</td>
<td>
<input type="hidden" value="#shoes.Id" id="hiddenval" />
#Html.HiddenFor(x => shoes.Id)
#Html.DisplayFor(x => shoes.Supply.SupplierName)
</td>
<td>
#shoes.ItemQty
</td>
<td>
#shoes.ItemUnitPrice
</td>
<td>
#Html.ActionLink("View", "Details", "Shoes", new { id=shoes.Id}, new { #class = "view-Modal",#data_toggle="modal" ,#data_target="#myModal"})
</td>
</tr>
}
</table>
#*Open Modal Testing*#
#section scripts
{
<script src="~/Scripts/jquery.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#myModal').hide();
$("#btn_Modal").click(function () {
$('#myModal').modal('show');
});
$(".view-Modal").click(function () {
var productId =
$(this).closest('tr').find('#hiddenval').val();
$.ajax({
type: 'POST',
url: '/Shoes/Details',
data: { id: productId },
success: function (response)
{
$('#modalBody').html(response);
$('#myModal').modal('show');
}
});
})
$(".close").click(function ()
{
console.log("Clear All");
});
});
</script>
}
partial view: _details
#model ShoeInformation.Models.Shoes
<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Details</h4>
</div>
<div class="modal-body">
<table class="tablemodel">
<tr>
<tr>
#Html.DisplayFor(x=>x.Id)
</tr>
<tr>
#Html.DisplayFor(x=>x.ProductName)
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
I try to breakpoint to see the problem but everything is working properly, however in the modal it display the same value
can someone please help me regarding to this matter
thanks in advance
Context
I'm developing a form in ASP.NET MVC 4 with Bootstrap 3 which displays an entity framework derived table. The table is read-only except that there is a button in the first column of each row allowing that row to be deleted.
My ViewModel:
public class SearchQueueViewModel
{
public List<SearchURL> SearchUrls { get; set; }
[Url(ErrorMessage = "Please provide a valid url")]
[MaxLength(500, ErrorMessage = "Url must be 500 characters or less")]
[Required]
public string NewUrl { get; set; }
}
The table is coded like this:
#model SearchQueueViewModel
#foreach (UserInterface.Models.SearchURL row in Model.SearchUrls)
{
<tr>
<td class="col-md-1 text-center">
#using (Html.BeginForm("delete", "home", FormMethod.Post, new { #class = "form-inline" }))
{
#Html.AntiForgeryToken()
<input type="hidden" value="#row" name="searchURL" />
<button type="submit" class="btn btn-xs">X</button>
}
</td>
<td class="col-md-2">#Html.DisplayFor(m => row.URL)</td>
<td class="col-md-2">#row.DateAdded.ToString("d-MMM-yy HH:mm")</td>
<td class="col-md-1">#Html.DisplayFor(m => row.Status)</td>
<td class="col-md-1">#Html.DisplayFor(m => row.SearchStarted)</td>
<td class="col-md-1">#Html.DisplayFor(m => row.SearchCompleted)</td>
<td class="col-md-1">#Html.DisplayFor(m => row.NumberOfProductsSearched)</td>
<td class="col-md-1">#Html.DisplayFor(m => row.NumberOfProductsFound)</td>
<td class="col-md-2">#Html.DisplayFor(m => row.FailErrorMessage)</td>
</tr>
}
In the controller I have:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(SearchURL searchURL)
{
context.SearchURLs.Remove(searchURL);
context.SaveChanges();
viewModel.SearchUrls = context.SearchURLs.ToList();
return View(viewModel);
}
Issue
The controller always receives a null object
Question
How do I get the searchURL object from the button-clicked row passed back to the controller correctly?
Note the for loop insted of foreach to enable model binding and the hidden fields to allow the values to be posted back to the controller. Change your view.
Your View:
#for (int i = 0; i < Model.SearchUrls.Count; i++)
{
<tr>
<td class="col-md-1 text-center">
#using (Html.BeginForm("delete", "home", FormMethod.Post, new { #class = "form-inline" }))
{
#Html.AntiForgeryToken()
#Html.HiddenFor(m=>Model.SearchUrls[i].SearchURLId)
<button type="submit" class="btn btn-xs">delete</button>
}
</td>
<td class="col-md-2">#Html.DisplayFor(m => Model.SearchUrls[i].SearchURLId.URL)</td>
<td class="col-md-2">#Model.SearchUrls[i].DateAdded.ToString("d-MMM-yy HH:mm")</td>
<td class="col-md-1">#Html.DisplayFor(m => Model.SearchUrls[i].Status)</td>
<td class="col-md-1">#Html.DisplayFor(m => Model.SearchUrls[i].SearchStarted)</td>
<td class="col-md-1">#Html.DisplayFor(m => Model.SearchUrls[i].SearchCompleted)</td>
<td class="col-md-1">#Html.DisplayFor(m => Model.SearchUrls[i].NumberOfProductsSearched)</td>
<td class="col-md-1">#Html.DisplayFor(m => Model.SearchUrls[i].NumberOfProductsFound)</td>
<td class="col-md-2">#Html.DisplayFor(m => Model.SearchUrls[i].FailErrorMessage)</td>
</tr>
}
And also change your Delete method.
public ActionResult delete(SearchQueueViewModel sm) // note this line
{
//your code
}
But the job is not finished yet. If I am not wrong now you are going to face issue with multiple submit button with identical property.
The best approach for your requirement is using javascript. You can have a look to this
I am trying to pass a userid to my action in controller .my action is like this as you can see here:
[HttpPost]
[Authorize(Roles = "Admin,Expert")]
public ActionResult AddExpert(AssistanceJuror assistanceJuror,int UserId)
{
User user = objUserRepository.FindBy(i => i.Id == assistanceJuror.UserId).First();
user.Enable = "فعال";
assistanceJuror.Date = DateTime.Now;
objUserRepository.Edit(user);
objUserRepository.Save();
objAssistanceJurorRepository.Add(assistanceJuror);
TempData["Message"] = "کارشناس به معاونت اختصاص داده شد";
objAssistanceJurorRepository.Save();
return RedirectToAction("IndexExpert", "Assistance");
}
So this action expect 2 parameters ,one of that is my model and another one is userId .so i need to get both values from the view my view is like this :
#using ViewModelDomain
#using Repository;
#model DomainClass.AssistanceJuror
#{
ViewBag.Title = "AddExpert";
}
#using (Html.BeginForm())
{
#Html.ValidationSummary(true)
<div class="wrapper-left">
<div class="wrapper-top-addCompany">
انتساب کارشناس به معاونت
<div style="float: left; padding-left: 20px;">
<div class="divider"></div>
<div class="buttonPossion">
#Html.ActionLink("بازگشت", "Index", "Assistance", new { companyid = ViewBag.firstIdeaId }, new { #class = "buttonBlueLink" })
</div>
<div class="divider"></div>
</div>
</div>
<div class="wrapper-Member" style="padding-bottom: 30px; margin-bottom: 5px; width: 100%; min-height: 550px;">
<h2>اضافه کردن کارشناس جدید
</h2>
<br />
<br />
<br />
<div class="editor-label">
انتخاب معاونت
</div>
<div class="editor-field">
#Html.DropDownListFor(model => model.AssistanceId, (SelectList)ViewBag.listAssistance)
</div>
<div class="editor-label">
انتخاب کارشناس
</div>
#* <div class="editor-field">
#Html.DropDownListFor(model => model.userId, (SelectList)ViewBag.listDisableExpert)
</div>*#
#{
if (User.IsInRole("Expert") || User.IsInRole("Admin"))
{
<div class="wrapper-Member" style="border-top: 1px solid #d3d3d3; margin-top: 30px; width: 99.5%; border-left: 1px solid #d3d3d3; margin-right: 1px">
<div class="tab-list-company" style="margin-right: -1px; width: 180px">
<h2 style="font: normal 13px BHoma; margin-right: 10px; margin-top: 2px;">اختصاص کارشناس به معاونت
</h2>
</div>
<div class="list-company" style="border: none; width: 98%">
<table>
<thead>
<tr>
<th>نام و نام خانوادگی</th>
<th>سطح تحصیلات</th>
<th>رشته تحصیلی</th>
<th>شماره همراه</th>
<th>تلفن</th>
<th>ایمیل</th>
#if (User.IsInRole("Expert") || User.IsInRole("Admin"))
{
<th style="width: 20px;">اضافه</th>
}
</tr>
</thead>
#{
userRepository objUserRepository = new userRepository();
//var listJuror = objUserRepository.FindBy(i => i.Permission == "Juror").ToList();
List<DomainClass.User> listDisableAssistance = objUserRepository.ReturnUserByEnablePermission("غیرفعال", "Assistance");
}
#foreach (var temp in listDisableAssistance)
{
<tr>
<td>
#{
string fullName = temp.Name + " " + temp.Family;
}
#Html.DisplayFor(modelItem => fullName)
</td>
<td>
#Html.DisplayFor(modelItem => temp.EducationLevel)
</td>
<td>
#Html.DisplayFor(modelItem => temp.Field)
</td>
<td>
#Html.DisplayFor(modelItem => temp.Mobile)
</td>
<td>
#Html.DisplayFor(modelItem => temp.Tell)
</td>
<td>
#Html.DisplayFor(modelItem => temp.Email)
</td>
<td>
#using (Html.BeginForm("AddExpert", "Assistance", routeValues: new { userid = temp.Id }))
{
<input type="submit" value="" class="Add" title="اضافه کردن" />
}
</td>
</tr>
}
</table>
</div>
</div>
}
}
</div>
</div>
}
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
In this part
<td>
#using (Html.BeginForm("AddExpert", "Assistance", routeValues: new { userid = temp.Id }))
{
<input type="submit" value="" class="Add" title="اضافه کردن" />
}
</td>
I am trying to pass my userId to my action but it doesn't work and i get an error that says the userid is null .
Best regards
I think that the problem is that you are not sending the assistanceJuror parameter to the controller.
new { userid = temp.Id }
should be
new {assistanceJuror= value, userid = temp.Id }
but I think that AssistanceJuror is a complex type so you'll get an error. Try sending only one id (for example) and get information from database in your controller.
Something like this
public ActionResult AddExpert(string assistanceJurorId,int UserId)
{
var assistanceJuror= //get Your Variable Here;
User user = objUserRepository.FindBy(i => i.Id == assistanceJuror.UserId).First();
user.Enable = "فعال";
assistanceJuror.Date = DateTime.Now;
objUserRepository.Edit(user);
objUserRepository.Save();
objAssistanceJurorRepository.Add(assistanceJuror);
TempData["Message"] = "کارشناس به معاونت اختصاص داده شد";
objAssistanceJurorRepository.Save();
return RedirectToAction("IndexExpert", "Assistance");
}
and call it in this way from the view
#using (Html.BeginForm("AddExpert", "Assistance", routeValues: new {assistanceJurorId= model.AssistanceId, userid = temp.Id }))
In this way you are not passing the selected value of the drop down list (that is stored in model.AssistanceId variable) to the controller
assistanceJurorId= model.AssistanceId
but the initial value of the property in the model because the drop down list is made in this way
#Html.DropDownListFor(x => x.AssistanceId, (SelectList)ViewBag.listAssistance))
To send the correct value of the selected element in the drop down list I suggest you to remove the Html. BeginForm and put an ajax call to your controller only on the submit of the form. In this way you are sure that the correct value will be send.
The best approach to MVC is to create a model in your GET method, use it in your View and POST the model in the Action that accept the Post verb. So, create a model class where you add all of your property (also the userid), in the view add at the top
#model YourClassModel
and your POST method
public ActionResult AddExpert(YourClassModel model)
I have the following Action method , which mainly display a list of objects and apply the IPaged list to it :-
[OutputCache(CacheProfile = "short", Location = OutputCacheLocation.Client,VaryByHeader="X-Requested-With" ,VaryByParam = "page")]
public ActionResult Index(int? typeid, int page = 1, string searchTerm ="")
{
int pagesize;
ViewBag.Techtypes = repository.GetAllTechnologyType2().ToList();
var audit = repository.AllIncludingTechnologyAudit(searchTerm.Trim(),typeid,auditinfo => auditinfo.Technology,auditinfo2=>auditinfo2.TechnologyType,auditinfo3=>auditinfo3.AuditAction).OrderByDescending(a=>a.ID)
.ToPagedList(page,300);
if (Request.IsAjaxRequest())
{
ViewBag.FromSearch = true;
return PartialView("_AuditTable", audit);
}
return View(audit);
}
The Index view looks as follow:-
model IPagedList<TMS.Models.TechnologyAudit>
#{
ViewBag.Title = "Technology Audit List";
}
<div style="float:right">
#using (Ajax.BeginForm("Index","TechnologyAudit",
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "Searchprogress",
UpdateTargetId = "AuditTable"
}))
{
<span class="f">Search By Tag</span> <input placeholder="Search by Tag.." name="searchTerm" type="text" />
<input class="btn btn-success" type="submit" value="search" />
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="Searchprogress" />
}
#using (Ajax.BeginForm("Index","TechnologyAudit",
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "Searchprogress2",
UpdateTargetId = "AuditTable"
}))
{
<span class="f">Asset Type</span>
#Html.DropDownList("typeid", ((IEnumerable<TMS.Models.TechnologyType>)ViewBag.Techtypes).Select(option => new SelectListItem {
Text = (option == null ? "None" :option.Name),
Value = option.AssetTypeID.ToString()
}), "All")
<input class="btn btn-success" type="submit" value="search" />
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="Searchprogress2" />
}
</div>
#Html.Partial("_AuditTable", Model)
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
And the _AuditTable view looks as follow:-
#model IPagedList<TMS.Models.TechnologyAudit>
<div id="AuditTable">
<div class="row-fluid sortable" >
<div class="box span12">
<div class="box-header well" data-original-title id="auditlist">
<h2><i class="icon-home"></i> Audit Info </h2>
<div class="box-icon">
<i class="icon-cog"></i>
<i class="icon-chevron-up"></i>
<i class="icon-remove"></i>
</div>
</div>
<div class="box-content">
<div class="pagedList" data-tms-target="#AuditTable">
#Html.PagedListPager(Model , page => Url.Action("Index", new { page }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "AuditTable" , LoadingElementId="progress2"}))
</div>
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" />
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model=>model.SingleOrDefault().UserName)
</th>
<th>
#Html.DisplayNameFor(model=>model.SingleOrDefault().AuditAction.Name)
</th>
<th>
#Html.DisplayNameFor(model=>model.SingleOrDefault().TechnologyType.Name)
</th>
<th>
#Html.DisplayNameFor(model=>model.SingleOrDefault().Technology.Tag)
</th>
</tr>
</thead>
<tbody>
#*#foreach (var item in Model.OrderByDescending(a=>a.DateTimeStart)) {
<tr>*#
#foreach (var item in Model) {
<tr>
<td>
#item.UserName
</td>
<td>
#(item.AuditAction == null ? "None" : item.AuditAction.Name)
</td>
<td>
#(item.TechnologyType == null ? "None" : item.TechnologyType.Name)
</td>
<td>
#Html.DisplayTextFor(_ => item.Technology.Tag).ToString()
</td>
</tr>
}
</tbody>
</table>
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress3" />
<div class="pagedList" data-tms-target="#ServerTable">
#Html.PagedListPager(Model , page => Url.Action("Index", new { page }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "AuditTable" , LoadingElementId="progress3"}))
</div>
</div></div></div></div>
Now If the user do a search using the searchTerm or the typeid the Ipaged will show number of pages equal to the objects that have the same typeid or the same searchTerm (for example Page 1 , Page 2). But when the user clicks on the page2 link , the paging will show all the objects and will ignore the typeid & the searchTerm, so how I can force the Ipaged list to do the paging on the records that was retrieved from the first action method call, which include the searchTerm or the typeid in the action method call?
It looks like the PagedListPager only submits the 'page'
#Html.PagedListPager(Model , page => Url.Action("Index", new { page }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "AuditTable" , LoadingElementId="progress2"}))
... you may want to try setting RouteValues
#Html.PagedListPager(Model , page => Url.Action("Index", new RouteValueDictionary()
{
{ "page", page },
{ "searchTerm", searchTerm },
{ "typeid", typeid}
}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "AuditTable" , LoadingElementId="progress2"}))
... this response is written on the fly ... untested ... a couple of three accepted answer links that may also point you the right direction:
ASP.NET MVC RouteValueDictionary and Complex Object
Create RouteValueDictionary on server and use in aspx?
RedirectToAction with parameter