开发者

How to get parameters out of an ascx back to the main aspx page

I've got an aspx page that renders an ascx page with filtering capabilities. Inside the ascx page, parameters are passed as follows:

<tr>
    <td class="label">Plataforma</td>
    <td class="field lookup"><%= Html.Lookup("s.Site", null, Url, "Sites") %></td>
</tr>
<tr>开发者_如何学Go
    <td class="label">Data</td>
    <td class="field date"><%= Html.TextBox("s.Date", DateTime.Today.ToString("yyyy-MM-dd")) %></td>
</tr>

I need to be able to get those parameters on the main aspx page, because they are needed for an action that is called there. How could I access these parameters?


Dy default the same Model is available to the page and all partial views on it so you should be able to get this values from the model. If this is not the case you can use the Items collection to pass values in the same request. In the ascx you can add the value to the items collection like this:

<% this.Context.Items.Add("myValue", myValue); %>

In the aspx you can access it like this:

<%= this.Context.Items["myValue"] %>

This method will work but it is not the right way in MVC world. You should perfectly pass all data using the Model and just display it on the views and partial views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜