Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (9)--Edit file name

Source: Internet
Author: User
Tags mysql code

Write in front

The previous article implemented the download of the file, this article will implement the function of editing the file name.

Series Articles

[Ef]vs15+ef6+mysql Code First mode

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (1)

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (2)--User Registration

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (3)--Verification code

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (4)--Upload Avatar

[Bootstrap]modal Popup box

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (5)--login interface, avatar and other proportional compression

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (5)--page template

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (5)--ajax mode registration

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (6)--ajax mode login

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (7)--File upload

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (8)--File download, delete

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (9)--Edit file name

Core code

Previous section Code

          <tbodyrole= "Alert"aria-live= "polite"aria-relevant= "All">@{int i = 0;}                    @foreach (var item in Model) {i++; <TRclass= "I%2==0?" Even ': ' Odd ' "ID= "[email protected]">                        <TDclass= "Even sorting_1"><imgsrc= "@item. Fileicon "alt="" /> <spanID= "[email protected]">@item. FileName</span></TD>                        <TDclass= "Center">@item. FileSize bytes</TD>                        <TDclass= "Center">@item. Modifydt</TD>                        <TDclass= "Center">                            <aclass= "Btn btn-success"href= "/home/[email protected]">                                <Iclass= "Glyphicon glyphicon-zoom-in icon-white"></I>Download</a>                            <aclass= "Btn btn-info"href= "javascript:void (0)"onclick= "Editfile" (@item. Id, ' @item. FileName ') ">                                <Iclass= "Glyphicon glyphicon-edit icon-white"></I>Edit</a>                            <aclass= "Btn Btn-danger"href= "javascript:void (0)"onclick= "DeleteFile" (@item. ID) ">                                <Iclass= "Glyphicon glyphicon-trash icon-white"></I>Delete</a>                        </TD>                    </TR>                }            </tbody>

Modal Pop-up box

<Divclass= "Modal Fade"ID= "Modal-edit"TabIndex= "-1"role= "Dialog"Aria-labelledby= "Mymodallabel"Aria-hidden= "true">    <Divclass= "Modal-dialog">        <Divclass= "Modal-content">            <Divclass= "Modal-header">                <Buttontype= "button"class= "Close"Data-dismiss= "Modal">X</Button>                <H3>Edit</H3>            </Div>            <Divclass= "Modal-body">                <inputtype= "text"placeholder= "Please enter a name"class= "Form-control"name= "Name"value=""ID= "Txtfilename" />            </Div>            <Divclass= "Modal-footer">                <ahref="#"class= "Btn Btn-default"Data-dismiss= "Modal"ID= "Lnkcancel">Cancel</a>                <ahref="#"class= "Btn btn-primary"Data-dismiss= "Modal"ID= "Lnksave">Save</a>            </Div>        </Div>    </Div></Div>

Request

    Edit file name    function editfile (fileId, filename) {        $ ("#txtFileName"). val (filename);        $ ("#modal-edit"). Modal (' show ');        The popup register cancels, saving the event        $ (' #lnkCancel '). Click (function () {            ///standalone Cancel, empty contents            $ ("#txtFileName"). Val (');        });        $ (' #lnkSave '). Click (function () {            var file = {                Fileid:fileid,                filenewname: $ (' #txtFileName '). Val ()            };            $.post ("/home/editfilename", file, function (data) {                data = json.parse (data);                if (Data.code = =) {                    $ (' #sp-' + fileId). HTML (file.filenewname);}});}        )    ;

Service-side code

         PublicJsonresult Editfilename () {stringfileid=request.form["fileId"]; stringfilenewname=request.form["Filenewname"]; UserInfo UserInfo= session["User"] asUserInfo; if(UserInfo = =NULL) {redirecttoaction ("Login","UserInfo"); }            intID =Convert.ToInt32 (fileId); varFindFile = _myfileservicerepository.find (x = = X.id = =ID); Findfile.filename=Filenewname;            _myfileservicerepository.update (FindFile); intCount =_myfileservicerepository.savechanges (); if(Count >0)            {                varResponse =New{Code= $, msg="Update Successful"                }; return NewJsonresult () {Data =NewJavaScriptSerializer ().            Serialize (response)}; }            return NewJsonresult () {Data =NewJavaScriptSerializer (). Serialize (New{Code = -, msg ="Save failed" }) }; }

Test

After the modification succeeds, the file name in the modified list is not refreshed.

Summarize

Come back from work, toss a code, the implementation of the edit file name operation.

Actual combat MVC5+EF6+MYSQL Enterprise Network Disk Combat (9)--Edit file name

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.