ASP. net mvc File Upload

Source: Internet
Author: User

The ASP. net mvc project that has been practiced over the past few days has encountered File Upload problems. Share the following:

View:

{
This. style. display = 'none'; document. getelementbyid ('Code _ closed_text_145457 '). style. display = 'none'; document. getelementbyid ('Code _ open_image_145457 '). style. display = 'inline'; document. getelementbyid ('Code _ open_text_145457 '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif "alt =" "width =" 11 "Height =" 16 "align =" TOP "> {
This. style. display = 'none'; document. getelementbyid ('Code _ open_text_145457 '). style. display = 'none'; getelementbyid ('Code _ closed_image_145457 '). style. display = 'inline'; getelementbyid ('Code _ closed_text_145457 '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif "alt =" "width =" 11 "Height =" 16 "align =" TOP "> View
1 <form action = "/adminimage/index/" method = "Post" enctype = "multipart/form-Data">
2 <div>
3 Please select a file to upload: & nbsp;
4 <input type = "file" id = "fileimage" name = "fileimage"/> & nbsp;
5 <input type = "Submit" value = "Upload"/>
6 </div>
7 </form>

 

Controller:

{
This. style. display = 'none'; document. getelementbyid ('Code _ closed_text_145657 '). style. display = 'none'; document. getelementbyid ('Code _ open_image_145657 '). style. display = 'inline'; document. getelementbyid ('Code _ open_text_145657 '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif "alt =" "width =" 11 "Height =" 16 "align =" TOP "> {
This. style. display = 'none'; document. getelementbyid ('Code _ open_text_145657 '). style. display = 'none'; getelementbyid ('Code _ closed_image_145657 '). style. display = 'inline'; getelementbyid ('Code _ closed_text_145657 '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif "alt =" "width =" 11 "Height =" 16 "align =" TOP "> Controller
1 Public actionresult index ()
2 {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 44_82_open_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 44_82_closed_imag '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 44_82_closed_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif "alt =" "align =" TOP "> {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 44_82_closed_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 44_82_open_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 44_82_open_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif "alt =" "align =" TOP "> {
3 return view ();
4}
5 [acceptverbs (httpverbs. Post)]
6 Public actionresult index (formcollection collection)
7 {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ cmd_745_open_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 2017_745_closed_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 2017_745_closed_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif "alt =" "align =" TOP "> {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 2017_745_closed_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ rj_745_open_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ cmd_745_open_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif "alt =" "align =" TOP "> {
8 If (request. Files. Count = 0)
9 {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 246_292_open_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 246_292_closed_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 246_292_closed_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif "alt =" "align =" TOP "> {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 246_292_closed_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 246_292_open_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 246_292_open_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif "alt =" "align =" TOP "> {
10 return view ();
11}
12 var c = request. Files [0];
13 if (C! = NULL & C. contentlength> 0)
14 {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 393_708_open_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 393_708_closed_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 393_708_closed_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif "alt =" "align =" TOP "> {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 393_708_closed_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 393_708_open_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 393_708_open_text '). style. display = 'inline ';
} "Src =" http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif "alt =" "align =" TOP "> {
15 int lastslashindex = C. filename. lastindexof ("//");
16 string filename = C. filename. substring (lastslashindex + 1, C. filename. Length-lastslashindex-1 );
17 filename = path. Combine (commonutility. docimagepath, filename );
18 C. saveas (filename );
19}
20 return view ();
21}

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.