views:

45

answers:

1

Hello all,

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

+3  A: 

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.

Darin Dimitrov
thats say that its no proper way to create controls in mvc?
Ragims
Properly speaking there's no such thing as *User Control* in ASP.NET MVC. There are Models, Controllers and Views. A View contains **only** markup (no C# as this belongs to your Model and Controller) and could be a full page .aspx or a partial .ascx. I would recommend you going through some of the tutorials here http://www.asp.net/mvc to get yourself familiarized with the basics.
Darin Dimitrov