[英]Asp Net MVC 5 refresh a table in a partial view
所以我遇到了一個小問題,我很難理解應該怎么做才能得到想要的/需要的結果。
因此,我的應用程序應該顯示路線在最近2小時內生成的某個對象。 當用戶加載該應用程序時,他們會看到分散在地圖上的幾個點,並且當他們單擊這些對象之一時,將顯示其在最近2小時內所做的路線,並且應該使用這些坐標來更新我擁有的表格。 現在,當我在controller方法中獲得對象所到達的所有位置時,我將進行調用以填充部分視圖。
這就是我開始所有這些的方式(當用戶單擊一個點時,將執行以下操作)
(我正在使用openlayers 3,但這與這個問題無關)
$.ajax({ type: "GET", url: '/Controller/GetRoutes', dataType: "json", success: function (result) { alert('Added'); var layerLines = new ol.layer.Vector({ source: new ol.source.Vector({ features: [ new ol.Feature({ geometry: new ol.geom.LineString(routes, 'XY'), name: 'Line' }) ] }) }); map.addLayer(layerLines); }, error: function (xhr, ajaxOptions, thrownError) { //some errror, some show err msg to user and log the error alert(xhr.responseText); } });
因此,從該代碼中您可以看到,方法GetRoutes()將負責獲取有關對象去往何處的信息。
這是控制器(我省略了大部分繪制實際路線的代碼,因為它有點笨拙)
[HttpGet]
public JsonResult GetRoutes()
{
var lastpoints = get an arraylist with all the points I want
var name = get the name of the object
RouteInformation(lastPoints,name);
return Json(lastPoints, JsonRequestBehavior.AllowGet);
}
我知道我可能應該在這里更改某些內容,但我不知道該怎么做。 給我最后一點的方法不是我的,但是我必須使用它,所以我別無選擇,只能接受它返回給我的arrayList。
這是RouteInformation方法
public ActionResult RouteInformation(ArrayList routeList, string name )
{
List<ObjPoint> routes = routeList.OfType<ObjPoint>().ToList();
List<ObjRoute> objRoutes = new List<ObjRoute>();
objRoutes.Add(new ObjRoute()
{
name = name,
ObjPoints = routes
});
return PartialView("RouteDetailsView", objRoutes);
}
我的問題是更新/刷新該表,我在局部視圖中有此表,但是我不知道要用我要顯示的信息更新該表時該怎么做(我可以得到我無法獲得的信息似乎證明了這一點)。
ObjPoint由緯度,經度,日期,時間組成。
這是ObjRoute模型
public class ObjRoute
{
public string name { get; set; }
public List<ObjPoint> ObjPoints { get; set; }
}
現在的意見...
這就是“主視圖”調用局部視圖的方式
<div> @Html.Partial("routeDetailsView") </div>
這是我的部分觀點
@model webVesselTracker.Models.ObjRoute @{ ViewBag.Title = "RouteDetailsView"; Layout = "~/Views/Shared/_Layout.cshtml"; } <div> <table id="routeTable" class="table"> <tr> <th> Name </th> <th> Latitude </th> <th> Longitude </th> <th></th> </tr> @if (Model != null) { foreach (var item in Model.ObjPoints) { <tr> <td> @Html.DisplayFor(modelItem => item.Latitude) </td> <td> @Html.DisplayFor(modelItem => item.Longitude) </td> </tr> } } else { <tr> <td> No object has been selected, please select one </td> </tr> } </table> </div>
現在我知道我可以通過在js文件中添加某種json請求並從那里構建表的方式來做到這一點,但是我想知道如何使用Razor做到這一點以及我在代碼/邏輯中出了錯的地方。 我應該在其他地方添加一些ajax嗎?
所以總結一下:
-User sees points.
-User clicks point to see the route it made.
-App draws the route and then sends the route information to a method table so it can be added to the table
the user can see that information
謝謝您的寶貴時間,如果我錯過了任何事情,請指出來,以便我更好地解決或解釋。
我終於放棄了,研究了ockout.js,它設法解決了我遇到的所有問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.