To develop a control, the function is relatively simple. To achieve this multi-choice function, a text box pops up when you click it. The data bound to the data table is displayed on the left, and the selected result is displayed on the right, the options are left and right. The functions are canceled and cleared, for example:
Use HtmlHelper to call:
<% =Html. MultiSelectFor (m=>M. CodeMC, m=>M. CodeDM,"Dm_jwrylbb","Dm <80",",",500,"Title",New{@ Style= "Width: 400px"})%>
Click "OK". The selected items are separated and saved to the text box. Key information (such as the ID of the displayed item) is saved to the hidden field.
The parameters are in the following order: text box ID, hidden domain ID, data table name, bound data table filter conditions, separator, pop-up layer height, title, htmlAttributes.
Idea: Create a text box and hide a domain control in htmlhelper. The text box control assigns an onfocus event. This event post calls PartialViewResult: ShowView (...), this action binds the model required for the pop-up layer, returns the control view, and fills it in the pop-up layer. Let's take a look at helper: (the length relationship does not list all heavy loads)
Standard htmlHelper: 1 Public Static MvcHtmlString MultiSelectFor < TModel, TValue > ( This HtmlHelper < TModel > Helper, Expression < Func < TModel, TValue > ExpressionMC, Expression < Func < TModel, TValue > ExpressionDM, String TableName, String Condition, String Split, Int Height, String Caption, Object McHtmlAttributes)
2 {
3 StringBuilder sb = New StringBuilder ();
4 String McString = ExpressionHelper. GetExpressionText (expressionMC );
5 String DmString = ExpressionHelper. GetExpressionText (expressionDM );
6
7 TagBuilder tag = New TagBuilder ( " Input " );
8 Tag. Attributes. Add ( " Type " , " Text " );
9 Tag. Attributes. Add ( " Name " , McString );
10 Tag. GenerateId (mcString );
11
12 Object McValue = ModelMetadata. FromLambdaExpression (expressionMC, helper. ViewData). Model;
13 String