문제

how the dropdown needs to be bound in professinal way? Does DropDown component need to be passed to BAL(business access layer)?

Please provide some code snippet and reference links..

도움이 되었습니까?

해결책

I usually will have a method in my Business Layer which returns a List of Custom class ( Ex : for State, I will have a State Class which has public properties like ID,Name,Code) .Then i will bind that to the drop down list

            List<State> objLstState =new List<State>();
            objLstState = StateManager.GetStates();  //This method returns a list of States
            if(objLstState!=null && objListState.Count>0)
            {
              dropDownSchoolState.DataSource = objLstState;
              dropDownSchoolState.DataTextField = "Name";
              dropDownSchoolState.DataValueField = "ID";
              dropDownSchoolState.DataBind();
            }

The above code executes in my UI layer (in a codebehind of an aspx page)

다른 팁

you can pass an array of the class holding your data .. the class should has public properties so they can be accessed and bound to your dropdownlist .. or which ever control you need to bind data to

The UI layer must deal with UI operations, same applies to the business layer that must deal with business operations. If you send your DropDown object to your business layer, you'll create a violation of principles that will only make your code messier, harder to mantain and more difficult to understand.

Since a DropDown control is something exclusively contained for the UI, I suggest that you request the data to be bound from your "business layer" and bind the control to the data inside your "UI layer".

On a short phrase: let the interactions between your layers deal with data, instead of information. A visual control is an information, an aggregation of data with a very specific use, dealing/containing operations, rules. A list of customer per se is just a list of customers, pure data, without any rules, operations or whatsoever.

No the dropdown surely does not need to be passed to any lower layer, the lower layers like BL or service layer should be eventually called by the UI (Presentation Layer) and consume the data retrieved, possibly with no dependency on the database technology or DAL logic used in the Data Access layer.

see this answer for some examples: MVC3 and Entity Framework

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top