In MVC How to pass a parameter to tabStrip when I was using Partial Views?

血红的双手。 提交于 2019-12-10 11:44:56

问题


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>&ordm;C</span></h2>
     <p>Rainy weather in Paris.</p>
  </div>
 <span class="rainy">&nbsp;</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(){

 }

回答1:


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.



来源:https://stackoverflow.com/questions/23597927/in-mvc-how-to-pass-a-parameter-to-tabstrip-when-i-was-using-partial-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!