开发者

how to access property in usercontrol.ascx from usercontrol.ascx.cs

开发者 https://www.devze.com 2023-01-14 12:19 出处:网络
I want create for paging a usercontrol. How can I access properties in usercontrol.ascx from usercontrol.ascx.cs?

I want create for paging a usercontrol.

How can I access properties in usercontrol.ascx from usercontrol.ascx.cs?

Property in usercontrol.ascx.cs:

 /// <summary>
        //开发者_开发知识库/ gets actual page index
        /// </summary>
        public int PageIndex
        {
            get
            {
                return _pageIndex;
            }
            set
            {
                _pageIndex = value;
            }
        }

usercontrol.ascx:

 <%= Html.RouteLink("<", new { page = (Model.PageIndex - 1) }, new { title = "previous page"})%>

How to access property? i have a model.PageIndex, but it doesnt works at all.

Thanks and tae care, Ragims


In ASP.NET MVC it is not common to have user controls and access their properties. You use the Model for this. There shouldn't even be a usercontrol.ascx.cs. So make this PageIndex a propery of your model.

0

精彩评论

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