在 MVC 中,如何在使用局部视图时将参数传递给 tabStrip? [英] In MVC How to pass a parameter to tabStrip when I was using Partial Views?
问题描述
在我的视图页面中,我有一个按钮.当我单击按钮时,我想让窗口打开.该窗口有一些标签条,在标签条中我想显示一个网格并将参数传递给网格.剑道用户界面允许我这样做吗?
Kendo Window--如何从我的主视图向_TabStrip传递参数?(比如参数是paraA"字符串)
@(Html.Kendo().Window().Name("窗口").Title("关于阿尔瓦·阿尔托").Content(@Html.Partial("_TabStrip").ToHtmlString()).Draggable().可调整大小().宽度(600).Actions(actions => actions.Pin().Minimize().Maximize().Close()).Events(ev => ev.Close("onClose"))
)
_TabStrip(局部视图)--如何将_TabStrip中的para传递给_Grid?(比如主视图中的参数是paraA"字符串)
@(Html.Kendo().TabStrip().Name("标签条").SelectedIndex(0).Items(items =>{items.Add().Text("巴黎").Content(@Html.Partial("_Weather").ToHtmlString());items.Add().Text("纽约").Content(@Html.Partial("_Grid").ToHtmlString());}))
_Weather(部分视图)
<h2>17<span>ºC</span></h2><p>巴黎的阴雨天气.</p><span class="rainy"> </span>
_Grid (Partial View)--如何从_tabStrip中获取参数?(比如参数是主视图中的paraA"字符串)
@(Html.Kendo().Grid().Name("网格").Columns(columns =>{column.Bound(c => c.ContactName).Width(140);column.Bound(c => c.ContactTitle).Width(190);column.Bound(c => c.CompanyName);columns.Bound(c => c.Country).Width(110);}).HtmlAttributes(new { style = "height: 380px;" }).Scrollable().Groupable().Sortable().Pageable(pageable => pageable.刷新(真).PageSizes(真).ButtonCount(5)).DataSource(dataSource => 数据源.Ajax().Read(read => read.Action("Customers_Read", "Grid").Data("GetParaFromMainView"))))//如何从主视图中获取参数函数 GetParaFromMainView(){}
你可以传递一个参数.但这需要您的观点有所改变.与从控制器传递模型的方式相同,它是相同的.需要修改或添加的行我会写.
主视图
这一行打开窗口:
.Content(@Html.Partial("_TabStrip").ToHtmlString())
致:
.Content(@Html.Partial("_TabStrip",paraA).ToHtmlString())
_TabStrip
在您的 _TabStrip.cshtml
视图中,您需要在顶部添加模型:
@model System.String//或只是字符串
...并更改此行:
.Content(@Html.Partial("_Grid").ToHtmlString());
到
.Content(@Html.Partial("_Grid",Model).ToHtmlString());
_网格
并在您的 _Grid.cshtml
顶部添加模型
@model System.String//或者只是字符串
并更改此行:
.Read(read => read.Action("Customers_Read", "Grid").Data("GetParaFromMainView")))
到
.Read(read => read.Action("Customers_Read", "Grid").Data(Model)))
我希望它能帮助您解决您的问题.使用 @Html.Partial
的重载来传递作为字符串的模型.试一试让我知道.
In my view page, I have a button. When I click the button, I want to make the window open. The window has some tabstrips, and in the tabstrip I want to show a grid and pass a parameter to the grid. Does kendo UI allow me to do this?
Kendo Window--How to pass a parameter to the _TabStrip from my main view?(like the parameter is "paraA" string)
@(Html.Kendo().Window()
.Name("window")
.Title("About Alvar Aalto")
.Content(@Html.Partial("_TabStrip").ToHtmlString())
.Draggable()
.Resizable()
.Width(600)
.Actions(actions => actions.Pin().Minimize().Maximize().Close())
.Events(ev => ev.Close("onClose"))
)
_TabStrip (Partial View) --How to pass a para from _TabStrip to _Grid?(like the parameter is "paraA" string from main view)
@(Html.Kendo().TabStrip()
.Name("tabstrip")
.SelectedIndex(0)
.Items(items =>
{
items.Add()
.Text("Paris")
.Content(@Html.Partial("_Weather").ToHtmlString());
items.Add()
.Text("New York")
.Content(@Html.Partial("_Grid").ToHtmlString());
})
)
_Weather (Partial View)
<div class="weather">
<h2>17<span>ºC</span></h2>
<p>Rainy weather in Paris.</p>
</div>
<span class="rainy"> </span>
_Grid (Partial View)--How to get the parameter from _tabStrip?(like the parameter is "paraA" string from main view)
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.CustomerViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ContactName).Width(140);
columns.Bound(c => c.ContactTitle).Width(190);
columns.Bound(c => c.CompanyName);
columns.Bound(c => c.Country).Width(110);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Customers_Read", "Grid").Data("GetParaFromMainView"))
)
)
//How to get the parameter from main View
function GetParaFromMainView(){
}
You can pass a parameter. But it will require some changes in your views. In the same way you pass the model from the controller it is the same. I will just write the lines who need to be changed or added.
Main View
This line to open the window:
.Content(@Html.Partial("_TabStrip").ToHtmlString())
To:
.Content(@Html.Partial("_TabStrip",paraA).ToHtmlString())
_TabStrip
In your _TabStrip.cshtml
view you need to add the model in the top:
@model System.String //or just string
... And change this line:
.Content(@Html.Partial("_Grid").ToHtmlString());
To
.Content(@Html.Partial("_Grid",Model).ToHtmlString());
_Grid
And in your _Grid.cshtml
add to the top too the model
@model System.String // or just string
And change this line:
.Read(read => read.Action("Customers_Read", "Grid").Data("GetParaFromMainView"))
)
To
.Read(read => read.Action("Customers_Read", "Grid").Data(Model))
)
I hopeit will help youto solve your problem. Use of an overload of @Html.Partial
to pass the model whichis your cas a string. Have a try a let me know.
这篇关于在 MVC 中,如何在使用局部视图时将参数传递给 tabStrip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!