TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
세림 김
NA
67
751
How to Enter Values ??in the Controller
Jan 11 2018 12:14 AM
I want to make a bulletin board with the same structure as the picture.
I will make it using the ASP.NET MVC5 pattern.
I have questions when creating.
Is there a way to create a table with tables and replies in a single table? Do I have to make two tables?
The second Family is the group number, which is the same as the post number.
The value is not entered when the controller is set to be the same.
The third depth is the order from the top-level article. 0 for posts.
However, you need to increase the moment you write your reply.
I have set the variable to increase in the controller and have increased it.
But it does not increase.
(ex, int i = 0; depth = i, depth = i++;)
How do we solve these problems?
I want to put the value in the controller registering the post as shown in the table below.
1. The column value of the article to be registered through writing is inserted as below.
Field Value
family ArticleIDX
parent 0
depth 0
indent 0
2. The column value of the article to be registered through reply writing is inserted as below.
Field Value
family Family of parent article
parent No of parent article
depth (depth of parent article) + 1
indent (indent of parent article) + 1
Controller to write posts.
<button type=
"button"
class
=
"btn btn-sm btn-lgr-str"
onclick=
"btnReply()"
>????</button>
<script >
function
btnReply()
{
location.replace(
"ReplyCreate"
);
}
</script>
[HttpGet]
public
ActionResult Create()
{
Articles article =
new
Articles();
return
View(article); }
[HttpPost]
public
ActionResult Create(Articles article)
{
try
{ article.Family = article.ArticleIDX;
//????
article.Parent = 0;
//??? ??
article.Depth = 0;
//??? ??? ???? ???? ??
article.Indent = 0;
//????
article.ModifyDate = DateTime.Now;
article.ModifyMemberID = User.Identity.Name;
db.Articles.Add(article);
db.SaveChanges();
if
(Request.Files.Count > 0)
{
var attachFile = Request.Files[0];
if
(attachFile !=
null
&& attachFile.ContentLength > 0)
{
var fileName = Path.GetFileName(attachFile.FileName);
var path = Path.Combine(Server.MapPath(
"~/Upload/"
), fileName);
attachFile.SaveAs(path);
ArticleFiles file =
new
ArticleFiles();
file.ArticleIDX = article.ArticleIDX;
file.FilePath =
"/Upload/"
;
file.FileName = fileName;
file.FileFormat = Path.GetExtension(attachFile.FileName);
file.FileSize = attachFile.ContentLength;
file.UploadDate = DateTime.Now;
db.ArticleFiles.Add(file);
db.SaveChanges();
}
}
ViewBag.Result =
"OK"
;
}
catch
(Exception ex)
{
Debug.WriteLine(
"Board"
);
Debug.WriteLine(ex.ToString());
ViewBag.Result =
"FAIL"
;
}
return
View(article);
//return RedirectToAction("ArticleList");
}
Controller to write reply.
[HttpGet]
public
ActionResult ReplyCreate()
{
Articles replyArticles =
new
Articles();
return
View(replyArticles);
}
[HttpPost]
public
ActionResult ReplyCreate(Articles replyArticles)
{
try
{
replyArticles.ModifyDate = DateTime.Now;
replyArticles.ModifyMemberID = User.Identity.Name;
db.Articles.Add(replyArticles);
db.SaveChanges(); ViewBag.Result =
"OK"
;
}
catch
(Exception ex)
{
ViewBag.Result =
"FAIL"
;
}
return
View(replyArticles);
}
The bulletin board model.
public
partial
class
Articles
{
[Key]
public
int
ArticleIDX {
get
;
set
; }
public
int
? Family {
get
;
set
; }
public
int
? Depth {
get
;
set
; }
public
int
? Indent {
get
;
set
; }
public
int
? Parent {
get
;
set
; }
[StringLength(200)]
public
string
Title {
get
;
set
; }
[Column(TypeName =
"text"
)]
public
string
Contents {
get
;
set
; }
[StringLength(50)]
public
string
Category {
get
;
set
; }
[StringLength(20)]
public
string
ModifyMemberID {
get
;
set
; }
public
DateTime? ModifyDate {
get
;
set
; }
public
virtual
Members Members {
get
;
set
; } }
Thank you......
Reply
Answers (
1
)
when click on build in visual studio appear Error message
how to find visitor current location using Asp.Net MVC ?