[英]Asp.Net Core - Pass Ckeditor textarea value to controller with Ajax?
I am using the ckeditor version 4 plugin ... I want to send ckeditot values to the controller but whatever I do sends a null value!!我正在使用 ckeditor 版本 4 插件......我想将 ckeditot 值发送到控制器,但无论我做什么都会发送一个空值!! I did a lot of searching, tried all the methods on the site, but it didn't work:( I downloaded the plugin again from the site but it still failed?
我做了很多搜索,尝试了网站上的所有方法,但没有奏效:(我从网站上再次下载了插件,但还是失败了?
Notice: When I use "Id" instead of "asp-for", the value is sent, but I need asp-for....注意:当我使用“Id”而不是“asp-for”时,会发送值,但我需要asp-for....
Html Form : html格式:
@model Baya.Core.ViewModels.AddProductViewModel
<form id="ProductForm" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label">desc</label>
<textarea asp-for="Description" class="form-control"></textarea>
</div>
<div class="modal-footer">
<button type="button" onclick="return ValidateForm()" class="btn btn-info waves-effect">save</button>
<button type="button" class="btn btn-danger waves-effect"
data-dismiss="modal">
cancel
</button>
</div>
JavaScript Code: JavaScript 代码:
$(function () {
/* $('#Description').ckeditor();*/
CKEDITOR.replace('Description');
});
function ValidateForm() {
let Form = $("#ProductForm")[0];
let Form_Data = new FormData(Form);
var descProduct = CKEDITOR.instances.Description.getData();
Form_Data.append("Description", descProduct);
$.ajax({
url: '/AdminPanel/Product/AddAndUpdateProduct',
data: Form_Data,
contentType: false,
processData: false,
type: 'POST',
success: function (data) {
//code
}
});
}
Controller :控制器 :
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult AddAndUpdateProduct(AddProductViewModel model)
{
//some code
}
I Used This Code:我使用了这个代码:
CKEDITOR.instances.Description.updateElement();
var descProduct = document.getElementById('Description').value;
Instead of this code:而不是这个代码:
var descProduct = CKEDITOR.instances.Description.getData();
It's worked成功了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.