请告诉我如何使用ASP.NEC MVC回答董事会

时间:2018-01-09 07:58:09

标签: asp.net asp.net-mvc-5

enter image description here

我想使用ASP.NET MVC来创建这样的公告板。 但我只是不知道,因为我刚学会了。 如果您有任何相关的代码或信息可以帮助我,您能告诉我吗? 以下是我的代码供参考。 我的控制器,视图,型号代码。 我不知道如何实现它。 请帮我。请。

[HttpGet]
    public ActionResult ReplyCreate()
    {
        ReplyArticles replyarticles= new ReplyArticles();
        return View(replyarticles);
    }

    [HttpPost]
    public ActionResult ReplyCreate(ReplyArticles replyArticles)
    {
        try
        {
            replyArticles.ReplyCategory = db.Articles.Where(m => m.ArticleIDX == replyArticles.ReplyArticleIDX).Select(m => m.Category).ToString();
            replyArticles.ReplyDepth = 1;
            replyArticles.ReplyIndent = 2;
            replyArticles.ReplyDate = DateTime.Now;
            replyArticles.ReplyMemberID = User.Identity.Name;

            db.ReplyArticles.Add(replyArticles);
            db.SaveChanges();

            ViewBag.Result = "OK";
        }
        catch (Exception ex)
        {
            ViewBag.Result = "FAIL";
        }
        return View(replyArticles);
    }

ReplyCreate View:
<div class="head_title text-center">
                    <h2>답글 작성</h2>
                    <div class="separator_auto"></div>
                </div>

                <form id="formdata" action="@Url.Action("ReplyCreate", "Board")" method="post" enctype="multipart/form-data">
                    <div class="row">
                        <div class="col-md-12">
                            <p>
                                <label>제목</label>
                                @Html.TextBoxFor(m => m.ReplyTitle, new { placeholder = "제목을 입력하세요." })
                                <a style="margin-left:52.5%"></a>
                            </p>
                        </div>
                        <div class="col-md-12" id="">
                            <label style="margin-right:78%;">분류</label>
                            <p>
                                @Html.DisplayTextFor(m => m.ReplyCategory)
                            </p>
                        </div>
                        <div class="col-md-12" style="margin-right: 100px;">
                            <br />
                            <p><label style="margin-right:550px;">내용</label>
                        </div>
                        <div class="col-md-12">
                            <p>
                                @Html.TextAreaFor(m => m.ReplyContents, new { placeholder = "내용을 입력하세요.", @rows = "10", @cols = "80" })
                            </p>
                        </div>
                        <div class="dividewhite2"></div>
                        <p>
                            <br />
                            <a style="margin-right:65px;"></a>
                            <button type="submit" onclick="return fnSaveReply();" class="btn btn-sm btn-lgr-str">등록하기</button>
                            <button type="button" class="btn btn-sm btn-lgr-str" onclick="javascript:history.go(-1);">목록이동</button>
                        </p>
                    </div>
                </form>
            </div>

Model : 
public partial class ReplyArticles
{
    [Key]
    public int ReplyIDX { get; set; }

    public int? ReplyArticleIDX { get; set; }

    public int? ReplyFamily { get; set; }

    public int? ReplyDepth { get; set; }

    public int? ReplyIndent { get; set; }

    [StringLength(200)]
    public string ReplyTitle { get; set; }

    [Column(TypeName = "text")]
    public string ReplyContents { get; set; }

    [StringLength(50)]
    public string ReplyCategory { get; set; }

    [StringLength(20)]
    public string ReplyMemberID { get; set; }

    public DateTime? ReplyDate { get; set; }
}

0 个答案:

没有答案