Follow as we do for Register starting from the controller, first add a controller named "logincontroller" in the "Controller" folder then replace it with the following code:
After successful login you will be shown your user name along with your image as follows, before that ensure you implement code for showing the image of the user logging in; we will implement that as follows.
You will see your "_Layout.cshtml" as follows:
- <img alt="" src="@Url.Action("GetPhoto", "User")" height="50" width="50" class="photo" />
This means we are trying to load the image from the "controller(User)" with the method or function name "GetPhoto"; change it as per your controller and method here. For a better understanding I will create a new controller and name it "displayImage" with the function "ShowImage" so my image source will be as follows:
now <img alt="" src="@Url.Action("ShowImage", "displayImage")" height="50" width="50" class="photo" />
Now let us create a controller and a view for logout. Create a controller and name it "Logout" and then replace your controller with the following:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace mvcForumapp.Controllers
- {
- public class LogoutController : Controller
- {
-
-
- public ActionResult Logout()
- {
- Session.Abandon();
- return RedirectToAction("Index", "Register");
- }
- }
- }
Now add a view by right-clicking on the "Logout" action result and select the master page. Your view should be as follows:
- @{
- ViewBag.Title = "Logout";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
-
- <h2>Logout</h2>
After successful log-out you will be routed to the main view again.
So far so good. Now let us create Controllers and Views for the rest, i.e posting questions, replies and all. First let us bring all the Questions from the database from each technology.
As we are using Entity Framework each and every Stored Procedure from the database is treated as a model, not only Stored Procedures but also tables.
First let us create a controller for displaying the list of technologies available and the number of topics and replies under each technology, also the last posted question information.
Create a controller and name it "Technology" and replace the code with the following code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace mvcForumapp.Controllers
- {
- public class TechnologyController : Controller
- {
-
-
- newForumDBEntities db = new newForumDBEntities();
- public ActionResult Index()
- {
- List<mvcForumapp.selectStats_Result_Result> userview = db.selectStats_Result().ToList();
- return View(userview);
- }
- }
- }
Create an empty View by right-clicking on "Index" and replace the view with the following:
- @model IEnumerable<mvcForumapp.selectStats_Result_Result>
- @{
- ViewBag.Title = "Main";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <div id="secondary_nav">
- <ul class="left" id="breadcrumb">
- <li class="first"><a href="">MVC-Forum Community</a></li>
- </ul>
- </div>
- <div class="clear" id="content">
- <a id="j_content"></a>
- <h2 class="hide">
- Board Index</h2>
- <div class="clearfix" id="board_index">
- <div class="no_sidebar clearfix" id="categories">
- <!-- CATS AND FORUMS -->
- <div class="category_block block_wrap">
- <h3 class="maintitle" id="category_47">
- <a title="View category" href="../Home/Main">Technology related questions</a></h3>
- <div class="table_wrap">
- <table summary="Forums within the category 'GimpTalk'" class="ipb_table">
- <tbody>
- <tr class="header">
- <th class="col_c_icon" scope="col">
-
- </th>
- <th class="col_c_forum" scope="col">
- Forum
- </th>
- <th class="col_c_stats stats" scope="col">
- Stats
- </th>
- <th class="col_c_post" scope="col">
- Last Post Info
- </th>
- </tr>
- <tr class="row1">
- <td class="altrow">
- </td>
- <td>
- @foreach (var item in Model)
- {
- string techname = item.TechName;
- @Html.ActionLink(techname, "Details", "Home", new { TechID = item.TechnID }, null)
- <br />
- <br />
- @Html.DisplayFor(modelItem => item.TechDesc)
- <br />
- <br />
- }
- </td>
- <td class="altrow stats">
- @foreach (var item in Model)
- {
- @Html.DisplayFor(modelItem => item.Totalposts)
- @Html.Label(" ");
- @Html.Label("Topics")
- <br />
- if (item.ReplyCount != null)
- {
- @Html.DisplayFor(modelItem => item.ReplyCount)
- @Html.Label(" ");
- @Html.Label("Replies")
- <br />
- <br />
- }
- else
- {
- @Html.DisplayFor(modelItem => item.ReplyCount)
- @Html.Label(" ");
- @Html.Label("0 Replies")
- <br />
- <br />
- }
- }
- </td>
- <td>
- @foreach (var item in Model)
- {
- if (item.DatePosted != null)
- {
- DateTime dt = Convert.ToDateTime(item.DatePosted);
- string strDate = dt.ToString("dd MMMM yyyy - hh:mm tt");
- @Html.Label(strDate)
- <br />
- }
- else
- {
- <br />
- }
- if (item.QuestionTitle != null)
- {
- @Html.Label("IN : ");
- @Html.Label(" ");
- string QuestionTitle = item.QuestionTitle;
- @Html.ActionLink(QuestionTitle, "displayIndividual", "Display", new { QuestionID = item.QuestionID }, null)
- <br />
- }
- else
- {
- <br />
- }
- if (item.Username != null)
- {
- @Html.Label("By : ");
- @Html.Label(" ");
- string User = item.Username;
- @Html.ActionLink(User, "Details", "Home", new { Username = item.Username }, null)
- <br />
- <br />
- }
- else
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Home", new { TechID = item.TechnID }, null)
- <br />
- <br />
- }
- }
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </div>
- </div>
Earlier I set the default routing view as Index from Register, so let us change that so when someone hits, the default view will be shown with the list of questions.
Changes in "RouteConfig.cs" that is in the "App_Start" folder:
- public static void RegisterRoutes(RouteCollection routes)
- {
- routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
-
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "Technology", action = "Index", id = UrlParameter.Optional }
- );
- }
This is how your view looks when you run the application:
Ok since I have questions in each and every Technology, this was displayed. Add a new technology in the tblTechnology table and run your application, when there are no question in that technology you will have a chance to post new questions in that technology.
Currently we haven't implemented anything for that; it will show an error page instead. We will see how to post new questions later on. First let me show you how to display all questions available in the selected Technology.
For the existing "Technology" controller I will add a few methods or you can add a new controller if you need to. I am adding the "a" method to the existing controller i.e "Technology" as follows:
- public ActionResult DisplayQuestions()
- {
- int TechID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
- List<mvcForumapp.QuestionList_Result> disp = db.QuestionList(TechID).ToList();
- return View(disp);
- }
Create a view by right-clicking on "DisplayQuestions" and replace it with the following code:
- @model IEnumerable<mvcForumapp.QuestionList_Result>
- @{
- ViewBag.Title = "Details";
- }
- <style type="text/css">
- .disabled
- {
-
- float: right;
- margin-right: 20px;
- background: #999;
- background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#dadada), to(#f3f3f3));
- border-top: 1px solid #c5c5c5;
- border-right: 1px solid #cecece;
- border-bottom: 1px solid #d9d9d9;
- border-left: 1px solid #cecece;
- color: #8f8f8f;
- box-shadow: none;
- -moz-box-shadow: none;
- -webkit-box-shadow: none;
- cursor: not-allowed;
- text-shadow: 0 -1px 1px #ebebeb;
- }
- .active
- {
- box-shadow: none;
- -moz-box-shadow: none;
- -webkit-box-shadow: none;
- cursor: allowed;
- }
- </style>
- <br />
- <br />
- <div style="float: left; margin-left: 20px;">
- @Html.ActionLink("Back", "Index", "Technology")
- </div>
- <div id='ipbwrapper'>
- <ul class="comRigt">
- <li>
- <br />
- <img alt="Start New Topic" src="http://www.gimptalk.com/public/style_images/master/page_white_add.png" />
- @if (Session["UserName"] != null)
- {
- int techID = Convert.ToInt16(@Request.QueryString["TechID"]);
- if (Model.Count() == 0)
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Question", new { @class = "active", onclick = "javascript:return true;", TechID = techID }, null)
- }
- else
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Question", new { @class = "active", onclick = "javascript:return true;", TechID = item.TechID }, null)
- break;
- }
- }
- }
- else
- {
- int techID = Convert.ToInt16(@Request.QueryString["TechID"]);
- if (Model.Count() == 0)
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Home", new {title = "Please login to post Questions", @class = "disabled", onclick = "javascript:return false;", TechID = techID })
- }
- else
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Home", new {title = "Please login to post Questions", TechID = item.TechID, @class = "disabled", onclick = "javascript:return false;" })
- break;
- }
- }
- }
- </li>
- </ul>
- <br />
- @if (Model.Count() != 0)
- {
- <div class="category_block block_wrap">
- <table id="forum_table" summary="Topics In This Forum "GimpTalk News and Updates""
- class="ipb_table topic_list">
- <div class="maintitle">
- <span class="main_forum_title">
- @foreach (var item in Model)
- {
- string strTopic = "A forum where you can post questions regarding " + item.TechName;
- @Html.Label("Topic", strTopic)
- break;
- }
- </span>
- </div>
- <tbody>
- <tr class="header">
- <th class="col_f_icon" scope="col">
-
- </th>
- <th class="col_f_topic" scope="col">
- Topic
- </th>
- <th class="col_f_starter short" scope="col">
- Started By
- </th>
- <th class="col_f_views stats" scope="col">
- Stats
- </th>
- <th class="col_f_post" scope="col">
- Last Post Info
- </th>
- </tr>
- <tr id="trow_49752" class="row1">
- <td class="short altrow">
- </td>
- <td class="__topic __tid49752" id="anonymous_element_3">
- @foreach (var item in Model)
- {
- <br />
- string QuestionTitle = item.QuestionTitle;
- @Html.ActionLink(QuestionTitle, "displayIndividual", "Display", new { QuestionID = item.QuestionID }, null)
- <br />
- <br />
- }
- </td>
- <td class="short altrow">
- @foreach (var item in Model)
- {
- <br />
- string QuestionTitle = item.UserName;
- @Html.ActionLink(QuestionTitle, "Details", "Home", new { Username = item.UserName }, null)
- <br />
- <br />
- }
- </td>
- <td class="stats">
- <ul>
- <li>
- @foreach (var item in Model)
- {
- @Html.DisplayFor(modelItem => item.ReplyCount)
- @Html.Label(" ");
- @Html.Label("Replies")
- <br />
- @Html.DisplayFor(modelItem => item.viewCount)
- @Html.Label(" ");
- @Html.Label("Views")
- <br />
- <br />
- }
- </li>
- </ul>
- </td>
- <td class="altrow">
- @foreach (var item in Model)
- {
- if (item.date != null)
- {
- DateTime dt = Convert.ToDateTime(item.date);
- string strDate = dt.ToString("dd MMMM yyyy - hh:mm tt");
- @Html.Label(strDate)
- }
- else
- {
- DateTime dt = Convert.ToDateTime(item.DatePosted);
- string strDate = dt.ToString("dd MMMM yyyy - hh:mm tt");
- @Html.Label(strDate)
- }
- <br />
- @Html.Label("By : ")
- @Html.Label(" ")
- if (item.RepliedName != null)
- {
- string User = item.RepliedName;
- @Html.ActionLink(User, "Details", "Home", new { Username = item.RepliedName }, null)
- }
- else
- {
- string User = item.UserName;
- @Html.ActionLink(User, "Details", "Home", new { Username = item.UserName }, null)
- }
- <br />
- <br />
- }
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- }
- else
- {
- <div class="category_block block_wrap">
- <table id="forum_table1" summary="Topics In This Forum "GimpTalk News and Updates""
- class="ipb_table topic_list">
- <div class="maintitle">
- <span style="font-size:larger; margin-left:450px;">No topics available</span>
- </div>
- </table>
- </div>
- }
- @if (Model.Count() != 0)
- {
- <ul class="comRigt">
- <li>
- <br />
- <img alt="Start New Topic" src="http://www.gimptalk.com/public/style_images/master/page_white_add.png" />
- @if (Session["UserName"] != null)
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Question", new { @class = "active", onclick = "javascript:return true;", TechID = item.TechID }, null)
- break;
- }
- }
- else
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Start New Topic", "PostQuestion", "Home", new {title = "Please login to post Questions", TechID = item.TechID, @class = "disabled", onclick = "javascript:return false;" })
- break;
- }
- }
- </li>
- </ul>
- }
- </div>
What will happen is, by selecting a particular technology in the image above will display all the questions related to that technology.
In this you can start a new Topic or post a new question if the user was logged in.
So far so good. Let us create the final step in this i.e creating questions and posting replies, first let us see how to create questions.
Create a class in the model with the name "Questions"; your class should be as follows:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.ComponentModel.DataAnnotations;
- namespace mvcForumapp.Models
- {
- public class Questions
- {
- [Required(ErrorMessage = "Title required")]
- [Display(Name = "Enter Title")]
- [StringLength(20, MinimumLength = 4)]
- public string TopicTitle { get; set; }
- [Required(ErrorMessage = "Description required")]
- [Display(Name = "Enter Description")]
- [StringLength(20, MinimumLength = 10)]
- public string TopicDescription { get; set; }
- [Required(ErrorMessage = "Content required")]
- [StringLength(Int32.MaxValue, MinimumLength = 10)]
- public string TopicContent { get; set; }
- }
- }
Create a controller with the name "Question" and replace the code with this:
- public class QuestionController : Controller
- {
- [HttpGet]
- public ActionResult PostQuestion()
- {
- int techID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
- return View();
- }
- }
This is how it is viewed when you route to the "PostQuestion" view:
Create another method in the same controller with HttpPost to post the question:
- [HttpPost]
- public ActionResult PostQuestion(mvcForumapp.Models.Questions user)
- {
- int techID = 0;
- if (ModelState.IsValid)
- {
- techID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
- using (var db = new newForumDBEntities())
- {
- var userdets = db.tblQuestions.CreateObject();
- userdets.TechID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
- userdets.QuestionTitle = user.TopicTitle;
- userdets.QuestionDesc = user.TopicContent;
- userdets.DatePosted = DateTime.Now;
- userdets.UserName = Session["UserName"].ToString();
- userdets.viewCount = 0;
- userdets.ReplyCount = 0;
- db.tblQuestions.AddObject(userdets);
- db.SaveChanges();
- return RedirectToAction("DisplayQuestions", "Technology", new { TechID = techID });
- }
- }
- return View(user);
- }
After a successful post you will be routed to the list of questions for that technology.
You can do the same for replys by creating a class in "Model" with a name called "Replys" and adding the necessary for that. This is how it is displayed when a post has replys.
For viewing the questions with replies add "View" and "Controller" correspondingly and your code should be as follows in the controller:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Data.SqlClient;
- using System.Data;
-
- namespace mvcForumapp.Controllers
- {
- public class Question_AnswerController : Controller
- {
- newForumDBEntities db = new newForumDBEntities();
- int vwcnt = 0;
-
- [HttpGet]
- public ActionResult displayQuestionwithAnswers()
- {
- var paramQuesID = new SqlParameter("@QuestionID", SqlDbType.Int);
- var paramRepCnt = new SqlParameter("@viewcount", SqlDbType.Int);
- int quesID = Convert.ToInt16(Request.QueryString["QuestionID"].ToString());
- paramQuesID.Value = quesID;
-
- var viewcount = db.tblQuestions.Where(e1 => e1.QuestionID == quesID).FirstOrDefault();
- vwcnt = viewcount.viewCount;
- if (vwcnt == 0)
- {
- vwcnt++;
- paramRepCnt.Value = vwcnt;
- var v = db.ExecuteStoreCommand("UPDATE tblQuestions SET viewCount = @viewcount WHERE QuestionID = @QuestionID", paramRepCnt, paramQuesID);
- }
-
- else
- {
- vwcnt = vwcnt + 1;
- paramRepCnt.Value = vwcnt;
- var v = db.ExecuteStoreCommand("UPDATE tblQuestions SET viewCount = @viewcount WHERE QuestionID = @QuestionID", paramRepCnt, paramQuesID);
- }
-
- List<mvcForumapp.Questionwithreplys_Result> disp = db.Questionwithreplys(quesID).ToList();
- return View(disp);
- }
-
- [HttpGet]
- public ActionResult GetPhoto()
- {
-
- int quesID = Convert.ToInt16(Request.QueryString["QuestionID"]);
- byte[] photo = null;
-
- var usrname = (from a in db.tblQuestions
- where a.QuestionID == quesID
- select new { a.UserName });
- var v = db.tblUsers.Where(p => p.UserName == usrname.FirstOrDefault().UserName).Select(img => img.Photo).FirstOrDefault();
- photo = v;
- return File(photo, "image/jpeg");
- }
- [HttpGet]
- public ActionResult ReplyPhoto()
- {
-
- int quesID = Convert.ToInt16(Request.QueryString["QuestionID"]);
- byte[] photo = null;
-
- var usrname = (from a in db.tblReplies
- where a.ReplyID == quesID
- select new { a.UserName });
- var v = db.tblUsers.Where(p => p.UserName == usrname.FirstOrDefault().UserName).Select(img => img.Photo).FirstOrDefault();
- photo = v;
- return File(photo, "image/jpeg");
- }
- }
- }
View for the corresponding controller:
- @model IEnumerable<mvcForumapp.Questionwithreplys_Result>
-
- @{
- ViewBag.Title = "Index";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <style type="text/css">
- .disabled
- {
-
- float: right;
- margin-right: 20px;
- background: #999;
- background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#dadada), to(#f3f3f3));
- border-top: 1px solid #c5c5c5;
- border-right: 1px solid #cecece;
- border-bottom: 1px solid #d9d9d9;
- border-left: 1px solid #cecece;
- color: #8f8f8f;
- box-shadow: none;
- -moz-box-shadow: none;
- -webkit-box-shadow: none;
- cursor: not-allowed;
- text-shadow: 0 -1px 1px #ebebeb;
- }
- .active
- {
- box-shadow: none;
- -moz-box-shadow: none;
- -webkit-box-shadow: none;
- cursor: allowed;
- }
- </style>
- <br />
- <div style="float: left; margin-left: 20px;">
- @foreach (var item in Model)
- {
- @Html.ActionLink("Back", "DisplayQuestions", "Technology", new { TechID = item.TechID }, null)
- break;
- }
- </div>
- <div class="topic_controls">
- <br />
- <ul class="comRigt" runat="server" id="lnkTopic">
- <li>
- <img alt="Add Reply" src="http://www.gimptalk.com/public/style_images/master/arrow_rotate_clockwise.png" />
- @if (Session["UserName"] != null)
- {
-
-
- foreach (var item in Model)
- {
- @Html.ActionLink("Add Reply", "PostReply", "Home", new { @class = "active", onclick = "javascript:return true;", QuestionID = item.QuestionID, TechID = item.TechID }, null)
- break;
- }
- }
- else
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Add Reply", "PostReply", "Home", new { title = "Please login to post replys", TechID = item.QuestionID, @class = "disabled", onclick = "javascript:return false;" })
- break;
- }
- }
- </li>
- </ul>
- <br />
- <h2 class="maintitle">
- <span class="main_topic_title">
- @foreach (var item in Model)
- {
- string strTopic = item.QuestionTitle;
- @Html.Label("Topic", strTopic)
- break;
- }
- </span>
- </h2>
- <br />
- <div class="post_wrap">
- <h3>
- <span class="author vcard">
- @foreach (var item in Model)
- {
- string User = item.quesaskedby;
- @Html.ActionLink(User, "Details", "Home", new { Username = item.quesaskedby }, null)
- break;
- }
- @*<asp:linkbutton id="lnkUsername" runat="server" text='<%#Eval("UserName") %>' font-underline="false"></asp:linkbutton>*@
- </span>
- </h3>
- <div class="authornew">
- <ul>
- <li class="avatar">
- @foreach (var item in Model)
- {
- <img alt="" src="@Url.Action("GetPhoto", "Question_Answer", new { QuestionID = item.QuestionID })" height="100" width="100" class="photo" />
- break;
- }
- </li>
- </ul>
- </div>
- <div class="postbody">
- <p class="postnew">
- @foreach (var item in Model)
- {
- DateTime dt = Convert.ToDateTime(item.DatePosted);
- string strDate = dt.ToString("dd MMMM yyyy - hh:mm tt");
- @Html.Label(strDate)
- break;
- }
- @*<asp:label id="lblDateposted" text='<%#Eval("DatePosted") %>' font-underline="false"
- runat="server" cssclass="edit"></asp:label>*@
- </p>
- <br />
- <br />
- <div class="post entry-content ">
- @*<asp:label id="Label1" text='<%#Eval("QuestionDesc") %>' font-underline="false" runat="server"
- cssclass="edit"></asp:label>*@
- @foreach (var item in Model)
- {
- @Html.Label(item.QuestionDesc)
- break;
- }
- </div>
- </div>
- </div>
- <br />
- <br />
- <br />
- <ul style="background-color: #e4ebf3; text-align: right; background-image: url(http:
- background-repeat: repeat-x; background-position: 40%; font-size: 1em; text-align: right;
- padding: 6px 10px 10px 6px; clear: both;">
- <li>
- <img alt="Add Reply" src="http://www.gimptalk.com/public/style_images/master/comment_add.png" />
- @if (Session["UserName"] != null)
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Add Reply", "PostReply", "Home", new { @class = "active", onclick = "javascript:return true;", QuestionID = item.QuestionID, TechID = item.TechID }, null)
- break;
- }
- }
- else
- {
- foreach (var item in Model)
- {
- @Html.ActionLink("Add Reply", "PostReply", "Home", new { title = "Please login to post replys", @class = "disabled", onclick = "javascript:return false;", TechID = item.QuestionID })
- break;
- }
- }
- @*<asp:linkbutton id="lnkpostReply" runat="server" onclick="lnkpostReply_Click" text="Reply"></asp:linkbutton>*@
- </li>
- </ul>
- </div>
- <br />
- <br />
- <div>
- @foreach (var item in Model)
- {
- if (item.ReplyUser != null)
- {
- <div class="topic_controls">
- <div class="post_wrap">
- <h3>
-
- @if (item.ReplyUser != null)
- {
- <span class="author vcard">
- @Html.ActionLink(item.ReplyUser.ToString(), "Details", "Home", new { Username = item.ReplyUser },
- null)</span>
- }
- <br />
- @*<asp:linkbutton id="lnkUsername" runat="server" text='<%#Eval("UserName") %>' font-underline="false"></asp:linkbutton>*@
- </h3>
- <div class="authornew">
- <ul>
- <li class="avatar">
- @if (item.ReplyID != null)
- {
- <img alt="" src="@Url.Action("ReplyPhoto", "Question_Answer", new { QuestionID = item.ReplyID })"
- height="100" width="100" class="photo" />
- }
- <br />
- </li>
- </ul>
- </div>
- <div class="postbody">
- <p class="postnew">
- @if (item.date != null)
- {
- @Html.Label(item.date.Value.ToString("dd MMMM yyyy - hh:mm tt"))
- }
- <br />
- @*<asp:label id="lblDateposted" text='<%#Eval("DatePosted") %>' font-underline="false"
- runat="server" cssclass="edit"></asp:label>*@
- </p>
- <br />
- <br />
- <div class="post
- entry-content ">
- @if (item.ReplyMsg != null)
- {
- @Html.Label(item.ReplyMsg)
- }
- <br />
- </div>
- @if (item.ReplyID != null)
- {
- <ul style="background-color: #e4ebf3; text-align: right; background-image: url(http:
- background-repeat: repeat-x; background-position: 40%; font-size: 1em; text-align: right;
- padding: 6px 10px 10px 6px; clear: both;">
- <li>
- <img alt="Add Reply" src="http://www.gimptalk.com/public/style_images/master/comment_add.png" />
- @*<asp:linkbutton id="lnkpostReply" runat="server" onclick="lnkpostReply_Click" text="Reply"></asp:linkbutton>*@
- @if (Session["UserName"] == null)
- {
-
- @Html.ActionLink("Add Reply", "PostReply", "Home", new { title = "Please login to post replys", @class = "disabled", onclick = "javascript:return false;", TechID = item.QuestionID })
-
- }
- else
- {
- @Html.ActionLink("Add Reply", "PostReply", "Home", new { @class = "active", onclick = "javascript:return true;", QuestionID = item.QuestionID, TechID = item.TechID }, null)
- }
- </li>
- </ul>
- }
- </div>
- </div>
- </div>
- }
- }
- </div>
The result is as follows:
That's it; the forums application is over.
Download the code and test it by creating the database with the given tables by adding the entity model to the application.
Check out my sample video for the demo, no audio in that just to show an overview of how the application runs.
If any queries please feel free to ask.