添加数组对象作为现有的控制器类方法的属性 [英] Add an Array object as a property of my existing Controller Class Method
问题描述
目前,我要么使用一个控制器类或formViewModel。控制器源的方法,我想添加的数组属性的对象太如下:
有谁知道我怎么会添加一个数组来此的ActionResult,这样从我查看我可以依次通过我的数组。我的数组,我想补充将包含来自客户端code地图对象上绘制坐标。
要做到这一点我一定要使用formViewModel并设置我的观点引用这个?如果我可以在阵列简单地传递与现有的code,那么巨大的。
公众的ActionResult IndexSearch(INT?页,串siteDescription)
{
const int的的pageSize = 10; //获取所有的网站
变种allSites = _siteRepository.FindAllSites(); //获取包含在sitedescription值的所有网站
VAR的SearchResult在allSites =(从s
其中,s.SiteDescription.StartsWith(siteDescription)
选择S); //返回局部视图的AJAX reults得到装入。
VAR paginatedSites =新PaginatedList<&网站GT;(SearchResult所,第53页1,pageSize的); 返回PartialView(SiteIndexSearchresults,paginatedSites);
}
我不明白是什么 formViewModel
你正在谈论。在示例code您提供的控制器动作传递一个的IEnumerable<网站>
收集到您的视图,让你可以通过它循环:
<%的foreach(在模型站点项){%GT;
< DIV><%:item.SiteDescription%GT;< / DIV>
<%}%GT;
甚至更好的使用显示模板,这个网站(〜/查看/主页/ DisplayTemplates / Site.ascx
)
<%@控制
语言=C#
继承=System.Web.Mvc.ViewUserControl&所述; SomeNs.Site>中
%GT;
< DIV><%:Model.SiteDescription%GT;< / DIV>
和中只需将主视图:
<%:Html.DisplayForModel()%GT;
At the moment I either use a controller class or a formViewModel. The controller source method that i'd like to add the array property object too is as follows:
Does anyone know how i would add an array to this ActionResult so that from my View i can loop through my array. My array that I add will contain coordinates that are to be plotted on a map object from client side code.
To do this do i have to use a formViewModel and set my view to reference this? If i can simply pass the array with the existing code then great.
public ActionResult IndexSearch(int? page, string siteDescription) {
const int pageSize = 10;
//Get all Sites
var allSites = _siteRepository.FindAllSites();
//Get all Sites that contain the value in sitedescription
var searchResults = (from s in allSites
where s.SiteDescription.StartsWith(siteDescription)
select s);
//Return partial view that the ajax reults get loaded into.
var paginatedSites = new PaginatedList<Site>(searchResults, page ?? 1, pageSize);
return PartialView("SiteIndexSearchresults", paginatedSites);
}
I don't understand what formViewModel
you are talking about. In the sample code you provided the controller action is passing an IEnumerable<Site>
collection to your view so that you could loop through it:
<% foreach (Site item in Model) { %>
<div><%: item.SiteDescription %></div>
<% } %>
or even better use a display template for this site (~/Views/Home/DisplayTemplates/Site.ascx
):
<%@ Control
Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<SomeNs.Site>"
%>
<div><%: Model.SiteDescription %></div>
And in your main view simply:
<%: Html.DisplayForModel() %>
这篇关于添加数组对象作为现有的控制器类方法的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!