Practical tips for using bootstrap DateTimePicker controls in asp.net mvc4

Source: Internet
Author: User

Some time ago wrote an article on the call Ali is larger than the SMS interface to develop the regular SMS mass notification function of the article http://www.jb51.net/article/94142.htm, the meeting time is the most important in the demand, it needs to meet the "format", "Easy input" At two points, developers who care about SMS costs should know that the length of the letter is the sum of two SMS charges, therefore, the regular time can not be arbitrary to the user to customize input, to consider the "easy to enter" point, you can only select the date selection control to assist user input, because the date selection control more compact use, in the page is not difficult to introduce. In this article, the use of Bootstrap DateTimePicker control, now bootstrap widely used, coupled with the project is also the bootstrap framework to quickly build the interface, so select this date control can also be more than the province resources, Here is a map of its effects:

Here I would like to share one of the problem-solving methods I encountered when introducing DateTimePicker resources, Here you need to introduce BOOTSTRAP-DATETIMEPICKER.CSS and bootstrap-datetimepicker.js, but before you introduce resources, you need to asp.net mvc BundleConfig.cs, to illustrate that this date control relies on jquery.js and bootstrap.js, these resource references sometimes have to be considered in order, should first be cited Jquery.js bootstrap.js is Bootstrap-dateti Mepicker.js. If you encounter a control click No response, you can use Firefox browser in the console to see the page encountered errors.

After the resource is referenced, the HTML structure is not said here. To be aware, there are sample HTML in the downloaded Control zip compression package, which is convenient for operations. Now solve the easy to enter the demand, and then the format, fortunately, the date control to get the date time is already standardized, but there is a problem, the choice of time is English, whether the need for Chinese is also a consideration of the direction.

The format for the time requirement in the project is as follows: October 04. Here does not consider the Chinese, in the background code in the string processing, get the expected time date. Here you can use Ajax to submit the date of your choice. Deal with the action first:

 Public ActionResult smssendformeeting (formcollection Form)
 { 
 string Operator = form[' Operator '];//Sender
 String Department =form["Department"];/department name
 String time = form[' time ']. ToString ()//Set time
 //Date
 format: "September 2016-08:30 pm"
 = sp. Dateparse (time);//Call date processing function 
 //Omit other extraneous code return
 View ();
 } 

This uses the Dateparse () method, which is a way to resolve date format conversions. The idea here is two, one is to remove the year and space, one is to convert the English month to the number of months, that is, string operation.

 public string Dateparse (string time) {//string time = ' January 2016-09:00 pm ';
 Time = Time.replace ("", "")//Remove space String day = time.substring (0, 2) + "days";//remove "th" int c = Time.lastindexof (":")-2;
 String detailtime = Time.substring (c);//specific to hour minutes int b = Time.lastindexof ("201");//This is not 2016 time = Time.remove (b);
  String month = Time.remove (0, 2);//month switch (month) {case "January": month = "January";
 Break
  Case "February": month = "February";
 Break
  Case "March": month = "March";
 Break
  Case "April": month = "April";
 Break
  Case "may": Month = "May";
 Break
  Case "June": month = "June";
 Break
  Case "July": Month = "July";
 Break
  Case "August": month = "August";
 Break
  Case "September": month = "September";
 Break
  Case "October": Month = "October";
 Break
  Case "November": month = "November";
 Break
  Case "December": Month = "December";
 Break
 String DateTime = month + day + detailtime;//get->9 month 18th 08:30pm return DateTime;


 }

Here is the switch () function and string operations such as substring, replace, indexof, remove, and so on, there are many ways of handling, here is the processing of strings from left to right. The Dateparse () function finally returns the October 4 required, which satisfies the requirement of "format" and "Easy input" for the regular SMS date. If my ideas and methods are wrong, I beg you to correct me and ask for advice.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.