Code Monkey home page Code Monkey logo

summernoteaspmvc5uploadimageexample's Introduction

ASP.MVC5 的Summernote的插入圖片

##Summer Note https://summernote.org/

編譯環境

  • Visual Studio 2017
  • Windows 10

##MVC5

  • 接收檔案的Action: /Home/UploadImage
  • 示範的Action: /Home/Index

##關鍵的Js Script

多數人卡在這邊:

$(document).ready(function () {
// Initialize Editor   
$('.textarea-editor').summernote(
{
    height: ($(window).height() - 300),         // set editor height  
    minHeight: null,       // set minimum height of editor  
    maxHeight: null,       // set maximum height of editor  
    focus: true,         
    callbacks: {
        onImageUpload: function (image) {
            editor = $(this);
            uploadImage(image[0], editor);
        }
    }
});
});

function uploadImage(file, editor) {
var data = new FormData();
data.append("image", file);
$.ajax({
    url: '/Home/UploadImage',
    cache: false,
    contentType: false,
    processData: false,
    data: data,
    type: "post",
    success: function (url) {
        editor.summernote('insertImage', 'http://' + url,'');
      },
      error: function(data) {
          console.log(data);
      }
  });
}

summernoteaspmvc5uploadimageexample's People

Contributors

wishnoblog avatar

Stargazers

Esengul Donmez avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.