Asp. Net MVC2 control development instance (2)

Source: Internet
Author: User

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 );

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.