Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc asp.net mvc tinymce的使用情况?_Asp.net Mvc - Fatal编程技术网

Asp.net mvc asp.net mvc tinymce的使用情况?

Asp.net mvc asp.net mvc tinymce的使用情况?,asp.net-mvc,Asp.net Mvc,剧本 控制器 model.Title // is my expected model.Description // is my expected model.Body // null public ActionResult\u AddPost() { 使用(NewsCmSenties实体=新的NewsCmSenties()) { //以下几行是正确的。我可以看到dropdownlist值。。。 ViewBag.PostTypes=new SelectLis

剧本

控制器

model.Title         // is my expected
model.Description   // is my expected
model.Body          // null
public ActionResult\u AddPost()
{
使用(NewsCmSenties实体=新的NewsCmSenties())
{
//以下几行是正确的。我可以看到dropdownlist值。。。
ViewBag.PostTypes=new SelectList(entity.PostTypes.ToList(),“Id”,“Name”);
ViewBag.Authors=new SelectList(entity.Authors.ToList(),“Id”,“Name”);
ViewBag.Categories=新选择列表(entity.Categories.ToList(),“Id”,“Name”);
返回PartialView(新的PostViewModel());
}
}
[HttpPost]
公共行动结果_AddPost(PostViewModel viewModel)
{
职位职位=新职位();
post=AutoMapper.Mapper.Map(viewModel);
PostImages postImage=新PostImages();
HttpPostedFileBase file=viewModel.file;
使用(NewsCmSenties实体=新的NewsCmSenties())
{
if(ModelState.IsValid)
{
//向数据库添加post
}
其他的
{
foreach(ViewData.ModelState.Values中的ModelState ModelState)
{
foreach(modelState.Errors中的ModelError错误)
{
控制台写入线(错误);
//错误消息模型。正文为空
}
}
}
所有的模型属性都是我期望的,唯一的主体属性不是。我缺少什么


感谢……

TinyMCE的诀窍在于它用iframe替换了textarea。对于标准帖子,TinyMCE自己处理原始textarea的更新,但当您使用AJAX时,您需要自己完成。这可以在使用的jQuery表单插件的
之前序列化
回调中完成:

public ActionResult _AddPost()
{
    using (NewsCMSEntities entity = new NewsCMSEntities())
    {
        // following lines are true. I can see dropdownlist values...
        ViewBag.PostTypes = new SelectList(entity.PostTypes.ToList(), "Id", "Name");
        ViewBag.Authors = new SelectList(entity.Authors.ToList(), "Id", "Name");
        ViewBag.Categories = new SelectList(entity.Categories.ToList(), "Id", "Name");

        return PartialView(new PostViewModel());
    }
}

[HttpPost]
public ActionResult _AddPost(PostViewModel viewModel)
{
    Posts post = new Posts();
    post = AutoMapper.Mapper.Map<PostViewModel, Posts>(viewModel);
    PostImages postImage = new PostImages();
    HttpPostedFileBase file = viewModel.File;

    using (NewsCMSEntities entity = new NewsCMSEntities())
    {
        if (ModelState.IsValid)
        {
             // add post to db
        }
        else
        {
            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                     Console.WriteLine(error);
                     // error message model.Body is null
                }
        }
   }

你能像FireBug中那样显示请求吗?我使用Ajax post,得到500个错误(内部服务器错误)。我调试了它,得到了模型状态错误(Body不应该为null)你能显示你在FireBug中看到的请求负载吗?@DarinDimitrov,我更新了我的问题。。对不起,我在你的问题中没有看到请求。你在更新的问题中显示的只是控制器动作,你在其中说
model.Body
为空,但我已经理解了。它为空的原因是因为您的请求可能是错误的。请显示FireBug中显示的确切HTTP请求。HTTP请求由标题和正文组成。这就是我需要看到的。使用FireBug的
网络
选项卡捕获它。
public class PostViewModel
{
    public int Id { get; set; }

    ...

    [Required(ErrorMessage = "{0} alanı boş bırakılmamalıdır!")]
    [Display(Name = "Haber İçerik")]
    [AllowHtml]
    public string Body { get; set; }

    ...

    [Required(ErrorMessage = "{0} alanı boş bırakılmamalıdır!")]
    [Display(Name = "Haber Tipi")]
    public Nullable<int> PostTypeId { get; set; }

    [Required(ErrorMessage = "{0} alanı boş bırakılmamalıdır!")]
    [Display(Name = "Yazar")]
    public Nullable<int> AuthorId { get; set; }

    [Display(Name = "Kategori")]
    public Nullable<int> CategoryId { get; set; }

    ...

    [Required(ErrorMessage = "{0} alanı boş bırakılmamalıdır!")]
    [Display(Name = "Yayında")]
    [DefaultValue(true)]
    public bool IsActive { get { return true; } set { } }

    public HttpPostedFileBase File { get; set; }
}
model.Title         // is my expected
model.Description   // is my expected
model.Body          // null
public ActionResult _AddPost()
{
    using (NewsCMSEntities entity = new NewsCMSEntities())
    {
        // following lines are true. I can see dropdownlist values...
        ViewBag.PostTypes = new SelectList(entity.PostTypes.ToList(), "Id", "Name");
        ViewBag.Authors = new SelectList(entity.Authors.ToList(), "Id", "Name");
        ViewBag.Categories = new SelectList(entity.Categories.ToList(), "Id", "Name");

        return PartialView(new PostViewModel());
    }
}

[HttpPost]
public ActionResult _AddPost(PostViewModel viewModel)
{
    Posts post = new Posts();
    post = AutoMapper.Mapper.Map<PostViewModel, Posts>(viewModel);
    PostImages postImage = new PostImages();
    HttpPostedFileBase file = viewModel.File;

    using (NewsCMSEntities entity = new NewsCMSEntities())
    {
        if (ModelState.IsValid)
        {
             // add post to db
        }
        else
        {
            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                     Console.WriteLine(error);
                     // error message model.Body is null
                }
        }
   }
$(function () {
    $('#form_post').ajaxForm({
        beforeSerialize: function($form, options) { tinyMCE.triggerSave(); },
        beforeSubmit: ShowRequest,
        success: SubmitSuccesful,
        error: AjaxError
    });
});