. Net programmers about MVC 2.0!

Source: Internet
Author: User

Is MVC better than webform? Not to mention the none. I personally think the biggest benefit of MVC is code concentration. High reuse rate. In particular, it is nice to use a strong visual view. Integration. Highly integrated.
Our project is still stuck in a combination of mvc2.0 + ado.net + webform (individual pages) + jquery. Share the MVC-based Brushless new upload control (no progress bar) that you have developed ).
This is a function call method: BaseUploadFile (1024*100, new List <string> () {"jpg", "jpeg", "png", "gif", "JPG ", "JPEG", "PNG", "GIF"}); parameter 1 indicates the size; parameter 2 indicates the suffix name.
Protected ActionResult BaseUploadFile (int Maxlength, List <string> postfix)
{
Try
{
HttpPostedFileBase httpfile = Request. Files ["FileMy"];
String [] str = httpfile. FileName. Split ('.');
String extion = str [str. Length-1];
Bool isExtion = false;
Foreach (string pos in postfix)
{
If (pos = extion)
{
IsExtion = true; break;
}
}
If (string. IsNullOrEmpty (extion) | (isExtion = false ))
{
Return Content ("1 ");
}
String saveUrl = "/upload/UploadMVC/" + Guid. NewGuid (). ToString () + "." + extion + "";
If (httpfile. ContentLength> Maxlength)
{
Return Content ("2 ");
}
Httpfile. SaveAs (Server. MapPath (saveUrl ));
Return Content (saveUrl );
}
Catch (Exception ex)
{
Return Content ("3 ");
}
}

The front-end code here uses a jquery plug-in Form. js du Niang.



 

This is the result.
View Code
<Script type = "text/javascript">
Function showResponse (responseText, statusText, xhr, $ form ){
If (responseText = "1 "){
Alert ("the upload format is incorrect! "); Return false;
}
If (responseText = "2 "){
Alert ("the size of the uploaded file exceeds the upload size limit! "); Return false;
}
If (responseText = "3 "){
Alert ("Upload error"); return false;
}
$ ("# NNimgUrl"). attr ("src", responseText );
}
Function sumbitFile (){
Var options = {
Success: showResponse
}
$ ('# MyForm1'). ajaxSubmit (options );
}
</Script>
<Form action = "/Form/uploadFile" method = "post" enctype = "multipart/form-data" id = "myForm1">
& nbsp; <input id = "FileMy" name = "FileMy" type = "file" style = "background-color: # D9D9D9; color: #009999 "/> <input id =" Button1 "onclick =" sumbitFile () "type =" button "value =" Upload "style =" background-color: #996633; color: # FFFFFF "/>
</Form>
<Div id = "dics"> </div>

 

From qingniu Ke

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.