Ad bit management under MVC+WCF frame--File upload

Source: Internet
Author: User

Advertising is one of the essential content of the site, but also directly to our site to bring economic benefits of one of the content. A good advertising position not only will not be strong, but will be the icing on our website, play the role of the finishing touch, so design a good advertising is also a major part of the development process.
Recently in a jewelry testing station project, where the management page is related to the ad bit management, before the project also has a lot of advertising, but not their own responsibility. The general idea is to upload the corresponding image from the Administration page, and to save to the database, and then select a display from all the uploaded images to the homepage of the website. The principle is not too difficult, but given the performance problem, we only need the database to save the image path.
The focus is in the framework of MVC+WCF, may be a little bit difficult, through the online friends of the sharing and communication within the team, to achieve the most basic upload and save database functions. The homepage of the site has five ads, due to the location of the ad position and the size of the different, of course, the charges are not the same, haha ~ ~ We initially design each ad bit has a separate management unit, my specific implementation is the AD bit Management page has five Datagrad, Each table is used to display the image path and the corresponding information for this type of ad position saved in the database.

Such as:

The table displays all of the database data and determines which ad image is displayed first by manipulating whether to display the radio button for the column. (The Name property of the radio button needs to be named uniformly, and the radio button of the whole table is set as a group)
Here we focus on the file upload, why only save the path in the database and not directly save the picture? First of all, this is the practice of most developers, and secondly, to some extent, it is better to save the path than the picture. I really realized in MVC, not much to say, directly on the code.

View

"FileUpLoad","AdvertisementManage",FormMethod.Post,new{enctype="multipart/form-data"type="text" name="AdvertisementName"type="file" name="file"type="submit" name="UploadFile" />}

Controller

         PublicActionResultFileUpLoad() {HttpPostedFileBase file = request.files["File"];//Get upload file            //Determine if the contents of the file are empty            if(File! =NULL)            {stringFilePath = Path.Combine (HttpContext.Server.MapPath (".. /images "), Path.getfilename (file. FileName));//Set File save pathFile. SaveAs (FilePath);//Save the file to the FilePath pathGuid g =NewGuid ("6DC3F7DB-F038-4C48-9564-0AC52E0E29C1");//Instantiate ViewModel, assign value to attributeAdvertisementmanageviewmodel advertisement=NewAdvertisementmanageviewmodel (); Advertisement.                Advertisementid=system.guid.newguid (); Advertisement. AdvertisementName = request.form["AdvertisementName"]; Advertisement.                Advertisementurl = FilePath; Advertisement.                TimeStamp = DateTime.Now; Advertisement.                UserID = g; Advertisement. Isenable =0;varService = Servicefactory.getservice ();//DECLARE WCF service                vars = service. Addadvertisement (advertisement);//Call the Add method on the service side to save the ad content to the database                //If saved successfully, return to FileUpload view                if(true)                {returnRedirecttoaction ("FileUpLoad","Advertisementmanage"); }            }Else{//return Content ("<script>alert (' upload failed! ') </script> ");                returnView (); }        }


These are the current implementation of the function, style and logic need to optimize, simple principle to share to everyone, there are shortcomings please criticize correct.

Copyright NOTICE: This article for Bo Master original article, reproduced please indicate the source, thank you!

Ad bit management under MVC+WCF frame--File upload

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.