简体   繁体   English

如何从局部视图获取父视图控件的引用

[英]How to get parent view control refrence from partial view

I have a view (name : view1), there are 2 controls. 我有一个视图(名称:view1),有2个控件。 one text box and other date picker. 一个文本框和其他日期选择器。 In the same view, i load a partial page (name: view2). 在同一视图中,我加载了部分页面(名称:view2)。

My question is how do i get reference to parent page's (view1) textbox and date picker control from partial page ? 我的问题是如何从部分页面引用父页面的(view1)文本框和日期选择器控件?

If you were talking about ASP.NET Webforms code behind files and you would like to access a control in the page via a user control object, you could use 如果您在谈论文件后面的ASP.NET Webforms代码,并且希望通过用户控件对象访问页面中的控件,则可以使用

Page.[property here]

In ASP.NET MVC you can pass data between code and views through the ViewBag property or the Model. 在ASP.NET MVC中,您可以通过ViewBag属性或模型在代码和视图之间传递数据。 Let's say that you have a partial view that has to receive some kind of data. 假设您有一个局部视图,必须接收某种数据。 You can define the object type of the data as @model [type] on top, and then pass the object from the main view with 您可以在顶部将数据的对象类型定义为@model [type],然后使用以下方法从主视图传递该对象:

@Html.RenderPartial("_name", modelobject)

Inside your partial view you can access that data using 在局部视图中,您可以使用

@Model.[property]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM