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}