Live search partialview loads as full view with Ajax.BeginForm - javascript

I´m trying to create a live search mechanism using Ajax and partialviews. The idea is that the main view is simply a text box without submit button (this is a main requirement for the program). The user types in the box and an onchange command activates a javascript function which submits the form into a controller. The controller will then make a database search and return a partialview filled with a table of results to substitute a div in the original view.
My problem is that the partialview with the results loads as a full view, over the index and search views.
These are my code snippets starting with the index view.
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div id="buscar">
#Html.Action("Buscar", "Reportes")
</div>
<div id="encontrar-form">
</div>
Now the partialview with the search button
#model IEnumerable<ProyectoTamaulipas.Reporte>
<script>
function showRes () {
document.getElementById("forma").submit();
}
</script>
<div>
<br />
<br />
<h2>Haga una búsqueda por número de folio</h2>
<p>
#using (Ajax.BeginForm("Buscar", "Reportes", FormMethod.Post, new AjaxOptions(){
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
UpdateTargetId = "encontrar-form"
}, new { id = "forma" }))
{
<input type="text" name="numero" onchange="showRes()" />
}
</p>
</div>
Now the relevant controllers
[HttpGet]
public ActionResult Buscar()
{
return PartialView("First");
}
[HttpPost]
public PartialViewResult Buscar(string numero)
{
if (numero != null)
{
int numeroF = 0;
//var query = (from a in db.Reporte
// where SqlMethods.Like(a.Calle1, "%" + parm + "%")
// select a).ToList();
List<Reporte> query = null;
if (Int32.TryParse(numero, out numeroF))
{
query = (from a in db.Reporte
where a.Folio == numeroF
select a).ToList();
}
return PartialView("reporte", query);
}
ViewBag.Message = "no se encontraron resultados";
return PartialView("reporte");
}
Finally the results view.
#model IEnumerable<ProyectoTamaulipas.Reporte>
#ViewBag.Message
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.UCivil_ID)
</th>
<th>
#Html.DisplayNameFor(model => model.ServicioID)
</th>
<th>
#Html.DisplayNameFor(model => model.Ubicacion)
</th>
<th>
#Html.DisplayNameFor(model => model.Calle1)
</th>
<th>
#Html.DisplayNameFor(model => model.Calle2)
</th>
<th>
#Html.DisplayNameFor(model => model.ColoniaID)
</th>
<th>
#Html.DisplayNameFor(model => model.Comentarios)
</th>
<th>
#Html.DisplayNameFor(model => model.EstatusID)
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.UCivil_ID)
</td>
<td>
#Html.DisplayFor(modelItem => item.ServicioID)
</td>
<td>
#Html.DisplayFor(modelItem => item.Ubicacion)
</td>
<td>
#Html.DisplayFor(modelItem => item.Calle1)
</td>
<td>
#Html.DisplayFor(modelItem => item.Calle2)
</td>
<td>
#Html.DisplayFor(modelItem => item.ColoniaID)
</td>
<td>
#Html.DisplayFor(modelItem => item.Comentarios)
</td>
#*<td>
#Html.DisplayFor(modelItem => item.Fotografia)
</td>*#
<td>
#Html.DisplayFor(modelItem => item.EstatusID)
</td>
</tr>
}
</table>
I already tried changing several commands and verifying the instalation of my unobtrusive ajax as well as several other things. Sorry for the long question but I've been going at this for two workdays with no luck. Thanks for the help!

I solved it by calling the jquery.unobtrusive-ajax.js on layout intead of on individual views and changing the
document.getElementById("forma").submit();
for a
$("#forma").trigger("submit");
on the search function inside the search partialview called First.

Related

How to display a modal without using the onClick function

I would like to know how I can open a modal without clicking on a button. Basically if a user searches for something and the search does not return an results I would like a modal to popup informing the user that the search did not yield any results. I have pasted my code below but I dont think I am supposed to be calling jquery from within html.
<table id="tableData" class="table">
<tr>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>
MobileNumber
</th>
<th>
EmailAddress
</th>
<th>
Identification Number
</th>
</tr>
#foreach (var item in Model)
{
if(Model.Count == 0)
{
$('#myConfirmationModal').modal('show');
//alert("no results find");
}
<tr>
<td>
<a class="anchorDetail" href="javascript:;" data-id=#item.ClientId>#item.FirstName</a>
</td>
<td>
#Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.MobileNumber)
</td>
<td>
#Html.DisplayFor(modelItem => item.EmailAddress)
</td>
<td>
#Html.DisplayFor(modelItem => item.IdentificationNumber)
</td>
</tr>
}
</table>
You basically need to execute $(#....).modal('show') after the page is loaded if the count is 0. Execute the code inside $(function(){...}). JQuery will make sure to execute the function inside $(...) after document is loaded i.e. same as $(document).ready(function(){...})
Try below.
if(Model.Count == 0) {
<script>
$(function() {
{
$('#myConfirmationModal').modal('show');
//alert("no results find");
}
});
</script>
} else {
#foreach (var item in Model) {
...
...
}

MVC5: How to filter based on selected drop down item [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 4 years ago.
This Question was marked as a duplicate to another post. That post addresses the "NullReference" Exception specifically and in great detail. It provides a lot of information specifically to and exclusively to the possible causes of NullReference Errors.
My Question is NOT specific to NullReference Errors. My question is "HOW TO FILTER RESULTS BASED ON SELECTED DROPDOWN BOX ITEMS". Certainly, along my course of trial and error - I encountered a NullReference error which was brought up here. But that's not the basis of my question. I am trying to do a specific function, that others may also find useful. (1) There may be better ways to accomplish my goal - and perhaps someone would share that. (2) we may resolve the NullReference error, only to find more errors that pop up. And therefore, this post is non specific to the NullReference Error, and specific to accomplishing the job of Filtering Results based on selected dropdown item. NullReference was just one of the errors along the way, in trying to accomplish the goal of the true question. So, I don't see this as a duplicate. But, it's fine.
How do I filter results, based on what is selected from a dropdown box? I am using MVC5, C# and javascript.
I found (what I think is) a good example online, and I modified it for my own use to test. Here is what I have so far
Index Controller:
public ViewResult Index()
{
var countries = new SelectList(
db.ICS_Units.Select(r => r.DeliveryUnit).Distinct().ToList());
ViewBag.Countries = countries;
return View();
}
Index View
#model IEnumerable<ICS20web.Models.ICS_Order_History>
#{
ViewBag.Title = "Index";
}
<fieldset>
<h2>Index</h2>
<div>
#Html.DropDownList("Countries", "select a Unit")
</div>
#{
Html.RenderPartial("OrderHistoryPartial", ViewData.Model);
}
<br />
<div id="target">
</div>
<div id="log">
</div>
</fieldset>
JavaScript added to Index View:
#Scripts.Render("~/Scripts/jquery-1.10.2.min.js")
<script type="text/javascript">
$(document).ready(function () {
$("#testList").change(function () {
$("#log").ajaxError(function (event, jqxhr, settings, exception) {
alert(exception);
});
var countrySelected = $("select option:selected").first().text();
$.get('#Url.Action("OrderHistoryPartial")',
{ id: countrySelected }, function (data) {
$("#target").html(data);
});
});
});
</script>
Partial View (OrderHistoryPartial):
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.DeliveryUnitID)
</th>
<th>
#Html.DisplayNameFor(model => model.LoginID)
</th>
<th>
#Html.DisplayNameFor(model => model.SuppliesID)
</th>
<th>
#Html.DisplayNameFor(model => model.OrderDate)
</th>
<th>
#Html.DisplayNameFor(model => model.ExpectedMonth)
</th>
<th>
#Html.DisplayNameFor(model => model.ExpectedYear)
</th>
<th>
#Html.DisplayNameFor(model => model.OrderedBy)
</th>
<th>
#Html.DisplayNameFor(model => model.OrderAmount)
</th>
<th>
#Html.DisplayNameFor(model => model.Measure)
</th>
<th>
#Html.DisplayNameFor(model => model.CurrentStatus)
</th>
<th>
#Html.DisplayNameFor(model => model.CurrentStatusDate)
</th>
<th>
#Html.DisplayNameFor(model => model.EmergencyOrder)
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.DeliveryUnitID)
</td>
<td>
#Html.DisplayFor(modelItem => item.LoginID)
</td>
<td>
#Html.DisplayFor(modelItem => item.SuppliesID)
</td>
<td>
#Html.DisplayFor(modelItem => item.OrderDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.ExpectedMonth)
</td>
<td>
#Html.DisplayFor(modelItem => item.ExpectedYear)
</td>
<td>
#Html.DisplayFor(modelItem => item.OrderedBy)
</td>
<td>
#Html.DisplayFor(modelItem => item.OrderAmount)
</td>
<td>
#Html.DisplayFor(modelItem => item.Measure)
</td>
<td>
#Html.DisplayFor(modelItem => item.CurrentStatus)
</td>
<td>
#Html.DisplayFor(modelItem => item.CurrentStatusDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.EmergencyOrder)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.OrderID }) |
#Html.ActionLink("Details", "Details", new { id = item.OrderID }) |
#Html.ActionLink("Delete", "Delete", new { id = item.OrderID })
</td>
</tr>
}
</table>
OrderHistoryPartial Controller:
public PartialViewResult OrderHistoryPartial(int id)
{
return PartialView(
db.ICS_Order_History.Where(r => r.DeliveryUnitID == id).OrderByDescending(r => r.OrderDate)
.ToList());
}
I think that I am VERY close to resolving this issue, but I have taken it as far as I can without asking for some help.
Currently, I get the following error:
Object reference not set to an instance of an object. Description:
An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference
not set to an instance of an object.
Source Error:
Line 43: Line 44: Line 45: #foreach (var item in Model)
Line 46: { Line 47:
I asked this question earlier today, but I have deleted that post because I think this is a bit more organized and provides more detailed information.
You are passing into your partial view ViewData.Model which is null because you are calling the view with no parameter. The 2 possible fixes are
Add the code to the IndexController.Index from OrderHistoryPartial.OrderHistoryPartial and return the model using view(result)
Call your Partial View with HTML.Action instead and pass an ID #html.Action("OrderHistoryPartial","OrderHistoryPartial",new { id = })

Display Details for Individual Items inside Tooltip on Mouse Hover

I am trying to display the details within a tooltip for each item in my index view. I would like the tooltip to appear when the mouse hovers over an items name. Currently I have some javascript and an view to go along with it. Any help or recommendations would be greatly appreciated!
Details Javascript:
$(document).load(function () {
for (var count = 0; count < 10; count++) {
$(document).tooltip({
items: "#j" + count,
content: function () {
return $("#i" + count).text();
}
});
};
});
Index View:
<table class="table">
<tr>
<th>
#Html.ActionLink("Software Name", "Index", new { sortOrder = ViewBag.SoftNameSort, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("License Type", "Index", new { sortOrder = ViewBag.LicenseType, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("End Date", "Index", new { sortOrder = ViewBag.EndDateSort, currentFilter = ViewBag.CurrentFilter })
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<noscript id="i#(count)">#Html.Partial("_SoftwareDetails", (WBLA.Models.SoftwareLicense)item)</noscript>
<td id="j#(count)">
#Html.DisplayFor(modelItem => item.SoftwareName)
</td>
<td>
#Html.DisplayFor(modelItem => item.LicenseType)
</td>
<td>
#Html.DisplayFor(modelItem => item.EndDate)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.SoftwareID }) |
#Html.ActionLink("Details", "Details", new { id = item.SoftwareID }) |
#Html.ActionLink("Delete", "Delete", new { id = item.SoftwareID })
</td>
</tr>
count++;
}
</table>
** EDIT **
I forgot to mention what I would like to show inside the tooltip. I would like to load a partial, which displays the relevant information for each item in my index view.
Partial Details View:
#model WBLA.Models.SoftwareLicense
<table>
<tr>
<th>
#Html.LabelFor(model => model.SoftwareName)
</th>
<td>
#Html.DisplayFor(model => model.SoftwareName)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.SoftwareKey)
</th>
<td>
#Html.DisplayFor(model => model.SoftwareKey)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.Price)
</th>
<td>
#Html.DisplayFor(model => model.Price)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.DepartmentName)
</th>
<td>
#Html.DisplayFor(model => model.DepartmentName)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.LicenseFilePath)
</th>
<td>
#Html.DisplayFor(model => model.LicenseFilePath)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.LicenseType)
</th>
<td>
#Html.DisplayFor(model => model.LicenseType)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.StartDate)
</th>
<td>
#Html.DisplayFor(model => model.StartDate)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.EndDate)
</th>
<td>
#Html.DisplayFor(model => model.EndDate)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.NotifyTime)
</th>
<td>
#Html.DisplayFor(model => model.NotifyTime)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.ConsumerEmail)
</th>
<td>
#Html.DisplayFor(model => model.ConsumerEmail)
</td>
</tr>
<tr>
<th>
#Html.LabelFor(model => model.EntryEmail)
</th>
<td>
#Html.DisplayFor(model => model.EntryEmail)
</td>
</tr>
</table>
* EDIT 8/03/2016 *
The title for the tooltip-tagged displays, however, my partial will not load within the tooltip.
Updated SoftwareDetails.js:
$(function () {
var url = '#Url.RouteUrl(new{ action="SoftwareDetails", controller="SoftwareLicense"})';
$(document).tooltip({
items: "td.myToolTips",
content: function (callback) {
$.get(url + "?id=" + $(this).data("id"))
.done(function (r) {
callback(r);
});
}
});
});
Updated Index View:
<table class="table">
<tr>
<th>
#Html.ActionLink("Software Name", "Index", new { sortOrder = ViewBag.SoftNameSort, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("License Type", "Index", new { sortOrder = ViewBag.LicenseType, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("End Date", "Index", new { sortOrder = ViewBag.EndDateSort, currentFilter = ViewBag.CurrentFilter })
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td class="myToolTips" data-id="#item.SoftwareID" title="Loading in a second..">
#item.SoftwareName
</td>
<td>
#Html.DisplayFor(modelItem => item.LicenseType)
</td>
<td>
#Html.DisplayFor(modelItem => item.EndDate)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.SoftwareID }) |
#Html.ActionLink("Details", "Details", new { id = item.SoftwareID }) |
#Html.ActionLink("Delete", "Delete", new { id = item.SoftwareID })
</td>
</tr>
//count++;
}
</table>
Updated SoftwareDetails Action:
public ActionResult SoftwareDetails(int id)
{
SoftwareLicense temp = db.SoftwareLicenses.Find(id);
return PartialView("SoftwareDetails", temp);
}
Result from URL Test (For Partial):
Partial Test
You do not need to render the tool tip partial view for all items when the page loads. You may get it on as needed basis. You can do this by making an ajax call and passing a unique id for the record user is hovering on currently.
Start by keeping a data attribute in your tr for the unique id.
#foreach (var item in Model)
{
<tr class="myToolTips" data-id="#item.SoftwareID" title="#item.SoftwareName">
<td>#item.SoftwareName</td>
</tr>
}
and you can enable tooltip for the table rows with the css class myToolTips.
$(function () {
$(document).tooltip({
items: "tr.myToolTips",
content: function (callback) {
$.get('/Home/SoftwareDetails/' + $(this).data("id"))
.done(function (r) {
callback(r);
});
}
});
});
Assuming you have an action method called SoftwareDetails which accepts the id and return the partial view
public ActionResult SoftwareDetails(int id)
{
return Content("Toolip for "+id);
// to do : Return the partial view for the markup you want (for the id)
}

Query Database Using JavaScript

I am fairly new to JavaScript and never used Ajax before. I want to add an OnClick to the Index.cshtml, so when a row is clicked, my code will query database (MSSQL)and return results.
I have two tables in database, User and Contact. The primary key in User, UID, is the foreign key in Contact. Here's my code:
Controller
private UserInfoEntities db = new UserInfoEntities();
public ActionResult Index(){
var users = from u in db.User orderby u.UID select u;
return View(users.ToList());
}
View
#<Info.Model.User>
<script type="text/javascript">
function showEmail() {
var tb = document.getElementById("users");
var rows = tb.rows;
for (var i = 1; i < rows.length; i++) {
rows[i].onclick = (function() {
//some code that query Contact table using UID
// and return Contact.Email in a popup windows or something
});
}
}
</script>
<table class="table" id="users" onclick="showEmail()">
<tr>
<th>
#Html.DisplayNameFor(model => model.NAME)
</th>
<th>
#Html.DisplayNameFor(model => model.UID)
</th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.NAME)
</td>
<td>
#Html.DisplayFor(modelItem => item.UID)
</td>
</tr>
Any help is appreciated!
try this;
<script type="text/javascript">
function showEmail() {
//some code that query Contact table using UID
// and return Contact.Email in a popup windows or something
}
</script>
<table class="table" id="users" >
<tr>
<th>
#Html.DisplayNameFor(model => model.FirstOrDefault().NAME)
</th>
<th>
#Html.DisplayNameFor(model => model.FirstOrDefault().UID)
</th>
</tr>
#foreach (var item in Model) {
<tr onclick="showEmail()">
<td>
#Html.DisplayFor(modelItem => item.NAME)
</td>
<td>
#Html.DisplayFor(modelItem => item.UID)
</td>
</tr>
}

Displaying details for master record using Javascript or jQuery in MVC4

I am trying to build a page with list of users. The goal is, that when you click "Details" link in the row, I would like to render partial view in the page using javascript or jQuery, So I dont need to reload the page. I have found many solutions (for example this), but I cant get it working, since I know next to nothing about javascript at the moment so I dont know how to connect what i found to code I have.
This is my partial view (i am not sure if it is correct as I wasnt able to even try to render it so far):
#model AdminDMS.Models.User
<h2>Details</h2>
<fieldset>
<legend>User</legend>
<div class="display-label">
#Html.DisplayNameFor(model => model.Guid)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.Guid)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.TrusteeType)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.TrusteeType)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.Username)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.Username)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.Email)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.Email)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.LastLogin)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.LastLogin)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.PasswordChanged)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.PasswordChanged)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.IsUsingTempPassword)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.IsUsingTempPassword)
</div>
</fieldset>`
I am using async controller, these are my Details async actions:
public void DetailsAsync(Guid guid)
{
if (userList == null || DateTime.Now > lastUpdate.AddMinutes(5))
{
AsyncManager.OutstandingOperations.Increment();
client.GetUsersAsync();
lastUpdate = DateTime.Now;
AsyncManager.Parameters["guid"] = guid;
}
}
public ActionResult DetailsCompleted(IEnumerable<AdminDMS.Models.User> users)
{
if (userList == null || !userList.Equals(users))
userList = users.ToList<AdminDMS.Models.User>();
return PartialView("Details", users.Single(user => user.Guid == (Guid)AsyncManager.Parameters["guid"]));
}
And this is the view:
#model List<AdminDMS.Models.User>
#{
ViewBag.Title = "Users";
}
<h2>Users</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Guid
</th>
<th>
Username
</th>
<th>
Email
</th>
<th>
TrusteeType
</th>
<th>
Last Login
</th>
<th>
Last Password Change
</th>
<th>
Temporary Password
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.Guid)
</td>
<td>
#Html.DisplayFor(modelItem => item.Username)
</td>
<td>
#Html.DisplayFor(modelItem => item.Email)
</td>
<td>
#Html.DisplayFor(modelItem => item.TrusteeType)
</td>
<td>
#Html.DisplayFor(modelItem => item.LastLogin)
</td>
<td>
#Html.DisplayFor(modelItem => item.PasswordChanged)
</td>
<td>
#Html.DisplayFor(modelItem => item.IsUsingTempPassword)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { item.Guid }) |
#*#Html.ActionLink("Details", "Details", new { item.Guid })*# |
#Html.ActionLink("Delete", "Delete", new { item.Guid })
</td>
</tr>
}
</table>
<div class="detailsDiv">
</div>
I would like to replace that commented out action link with something, that will render the partial view in "detailsDiv" div that is left empty at the end.
Thanks in advance
UPDATE:
My controller now has this action
public PartialViewResult Details(Guid guid)
{
AdminDMS.Models.User user = null;
UserService.User serviceUser = client.GetUsers().Single(u => u.Guid == guid);
user = new AdminDMS.Models.User(serviceUser.Guid, serviceUser.TrusteeType, serviceUser.Username, serviceUser.Email, serviceUser.LastLogin, serviceUser.PasswordChanged, serviceUser.IsUsingTempPassword);
return PartialView("_detailsPartial", user);
}
_detailsPartial is the detail view (that hasnt changed at all)
this is the current call to controller in view:
#Ajax.ActionLink("Details", "Details", item, new AjaxOptions { UpdateTargetId = "detailsDiv", InsertionMode = InsertionMode.Replace})
This is the div I want to update:
<div id="detailsDiv">
</div>
There is nothing else in the view after this div.
Current result is that the link will open new page in the window and renders partial view (with item details as content)
I always use this to render a partial view with ajax, this works, if you have any other problems, it is something else :)
#Ajax.ActionLink("blabla", "DetailsCompleted", new { Users= "add users here" }, new AjaxOptions { UpdateTargetId = "detailsDiv"})
EDIT: CONTROLLER action
public PartialViewResult yourpartialname("data here")
{
"get your data
return PartialView(data);
}
EDIT 2:
You can do this:
#Ajax.ActionLink("Details", "Details", new {item = item.Guid}, new AjaxOptions { UpdateTargetId = "detailsDiv", InsertionMode = InsertionMode.Replace})
I know this will work, but I don't know if it's a big difference (I'm not that pro either :)), again, I don't know if its a big difference but you can change your partialview result to this:
public PartialViewResult DetailsPartial(Guid item)
{
AdminDMS.Models.User user = null;
UserService.User serviceUser = client.GetUsers().Single(u => u.Guid == guid);
user = new AdminDMS.Models.User(serviceUser.Guid, serviceUser.TrusteeType, serviceUser.Username, serviceUser.Email, serviceUser.LastLogin, serviceUser.PasswordChanged, serviceUser.IsUsingTempPassword);
return PartialView(user);
}
Where DetailsPartial is the name of your partial view
You can try this, I would do it this way, else I don't see any problems with your code
LAST EDIT
</footer>
#Scripts.Render("~/bundles/jquery")
<script src="#Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
#RenderSection("scripts", required: false)
</body>
</html>
I suppose the most appropriate thing to use for rendering just a part of the page is AJAX.
http://en.wikipedia.org/wiki/Ajax_(programming)
Honestely I'm not a pro in Asp.net but I suppose there is a tool kit that does the trick. http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/

Categories

Resources