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


Controller

        Public ActionResult FileUpLoad () {httppostedfilebase file = request.files["file"];//get upload file Determines whether the contents of the file are empty if (file! = null) {string filePath = Path.Combine (httpcontext.s Erver. MapPath (".. /images "), Path.getfilename (file. FileName)); Set file save path.                SaveAs (FilePath);//Save the file to the FilePath path under the GUID g = new GUID ("6dc3f7db-f038-4c48-9564-0ac52e0e29c1");                Instantiate the ViewModel, assign a value to the attribute Advertisementmanageviewmodel advertisement=new Advertisementmanageviewmodel (); Advertisement.                Advertisementid=system.guid.newguid (); Advertisement.                AdvertisementName = request.form["AdvertisementName"]; Advertisement.                Advertisementurl = FilePath; Advertisement.                TimeStamp = DateTime.Now; Advertisement.                UserID = g; Advertisement.                isenable = 0;      var service = Servicefactory.getservice ();//declaring WCF Services          var s = service.                Addadvertisement (advertisement);///Invoke the Add method on the service side to save the ad content to the database//If the save is successful, return to FileUpload view if (true)                {return redirecttoaction ("FileUpLoad", "advertisementmanage"); }} else {//return Content ("<script>alert (' upload failed!                ') </script> ");            return View (); }        }


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.

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


Controller

        Public ActionResult FileUpLoad () {httppostedfilebase file = request.files["file"];//get upload file Determines whether the contents of the file are empty if (file! = null) {string filePath = Path.Combine (httpcontext.s Erver. MapPath (".. /images "), Path.getfilename (file. FileName)); Set file save path.                SaveAs (FilePath);//Save the file to the FilePath path under the GUID g = new GUID ("6dc3f7db-f038-4c48-9564-0ac52e0e29c1");                Instantiate the ViewModel, assign a value to the attribute Advertisementmanageviewmodel advertisement=new Advertisementmanageviewmodel (); Advertisement.                Advertisementid=system.guid.newguid (); Advertisement.                AdvertisementName = request.form["AdvertisementName"]; Advertisement.                Advertisementurl = FilePath; Advertisement.                TimeStamp = DateTime.Now; Advertisement.                UserID = g; Advertisement.                isenable = 0;      var service = Servicefactory.getservice ();//declaring WCF Services          var s = service.                Addadvertisement (advertisement);///Invoke the Add method on the service side to save the ad content to the database//If the save is successful, return to FileUpload view if (true)                {return redirecttoaction ("FileUpLoad", "advertisementmanage"); }} else {//return Content ("<script>alert (' upload failed!                ') </script> ");            return View (); }        }


The above is the MVC+WCF framework under the AD bit management-file upload content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.