HI
it is my Controller in ViewNews :
private NezamDB db = new NezamDB();
PersianCalendar persian = new PersianCalendar();
NewsViewModel Mod;
//
// GET: /ViewNews/
[HttpGet]
public ActionResult Index(int id)
{
some code is hiden....
var model = (from r in db.News.AsEnumerable()
where r.Id==id
select new NewsViewModel
{
Body = r.Body,
Comments = r.Comments,
Education = r.Education,
Financial = r.Financial,
Id = r.Id,
ImageUrl = r.ImageUrl,
Notic = r.Notic,
Public = r.Public,
Refahi = r.Refahi,
Special = r.Special,
Summary = r.Summary,
Title = r.Title,
Visitors = r.Visitors,
CreateDate = ((persian.GetYear(r.CreateDate) + "/" + persian.GetMonth(r.CreateDate) + "/" + persian.GetDayOfMonth(r.CreateDate))),
UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
}).SingleOrDefault();
string s="";
if (model == null)
{
return HttpNotFound();
}
else
{
Mod = new NewsViewModel();
Mod.Id = model.Id;
Mod.ImageUrl = model.ImageUrl;
Mod.Notic = model.Notic;
Mod.Public = model.Public;
Mod.Refahi = model.Refahi;
Mod.Special = model.Special;
Mod.Summary = model.Summary;
Mod.Title = model.Title;
Mod.UpdateDate = model.UpdateDate;
Mod.Visitors = model.Visitors;
s=model.Body;
Mod.Body = s.Replace("\n", "<" + "br/" + ">");
Mod.Comments = model.Comments;
Mod.CreateDate = model.CreateDate;
Mod.Education = model.Education;
Mod.Financial = model.Financial;
}
Visitors visit = new Visitors();
visit.Name = visitorIPAddress.ToString();
visit.NewsId = id;
db.Visitors.Add(visit);
db.SaveChanges();
return View(Mod);
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
and it is View :
@model NewsViewModel
@{
ViewBag.Title = "مشاهده خبر";
}
<!--
<h1>@Model.Title</h1>
<span>تاریخ ایجاد: @Model.CreateDate</span> |
<span>تاریخ آخرین ویرایش: @Model.UpdateDate</span> |
<span>تعداد بازدید: @Model.Visitors.Count()</span>
<hr />
<br />
<img class="imgr" src="@Model.ImageUrl" />
@Html.Raw(System.Web.HttpUtility.HtmlDecode(@Model.Body))
<!--
@Html.Partial("_Index", Model.Comments)
@*@Html.Partial("_IndexSendCommend", new {model=new Comments() }.model)*@
@Html.Action("create", "Comment", new { NewsId = Model.Id })
it is partial view :
@model IEnumerable<Comments>
<div id="comments">
<hr />
<br />
<h2>نظرات ارسال شده</h2>
<ul class="commentlist">
@foreach (var item in Model)
{
if ((item.Id % 2) == 0)
{
<li class="comment_odd">
<div class="author">
<img class="avatar" src="~/images/demo/avatar.gif" width="32" height="32" alt="" /><span class="wrote">نویسنده:</span><span class="name">@item.Name</span>
</div>
<div class="submitdate"><a href="#">@item.DateCreat</a></div>
@{
string s = @item.Body;
s = s.Replace("\n", "<" + "br/" + ">");
<p>@Html.Raw(System.Web.HttpUtility.HtmlDecode(s))</p>
}
</li>
}
else
{
<li class="comment_even">
<div class="author">
<img class="avatar" src="~/images/demo/avatar.gif" width="32" height="32" alt="" /><span class="wrote">نویسنده:</span><span class="name"><a href="#">@item.Name</a></span>
</div>
<div class="submitdate"><a href="#">@item.DateCreat</a></div>
@{
string s = @item.Body;
s = s.Replace("\n", "<" + "br/" + ">");
<p>@Html.Raw(System.Web.HttpUtility.HtmlDecode(s))</p>
}
</li>
}
}
</ul>
</div>
it is controller in action link command:
[HttpGet]
[ValidateInput(false)]
public ActionResult Create(int NewsId)
{
return PartialView();
}
[HttpPost]
[ValidateInput(false)]
public ActionResult Create(Comments comments)
{
{
comments.DateCreat = DateTime.Now.ToShortDateString();
if (ModelState.IsValid)
{
db.Comments.Add(comments);
db.SaveChanges();
ModelState.Clear();
ControllerContext.HttpContext.Response.Redirect(Request.UrlReferrer.ToString());
}
}
return PartialView();
}
and it is view'command
@model Nezam.Models.Comments
@{
ViewBag.Title = "Create";
}
<h2>ارسال نظرات </h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset class="fieldset">
<legend class="legend">ارسال نظر</legend>
<p>
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name, new { Size = "22" })
@Html.ValidationMessageFor(model => model.Name)
</p>
<p>
@Html.LabelFor(model => model.Email,new { Style = "margin-left:52px" })
@Html.EditorFor(model => model.Email, new { Size = "22" })
@Html.ValidationMessageFor(model => model.Email)
</p>
<p>
@Html.LabelFor(model => model.Body)
</p>
<p>
@Html.TextAreaFor(model => model.Body, new { cols = "100%", rows = "10" })
@Html.ValidationMessageFor(model => model.Body)
</p>
<p>
<input type="submit" value="ارسال" />
</p>
</fieldset>
}
@section Scripts {
}
i run my project and i see my page' viewnews but when i click on submit button in action link in command partial view give me this error :
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /ViewNews/Index/3012
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34009
I set the starting page URL in properties->web->specificpage.
It throws me the above mentioned error.
I couldnt find the reason behind this issue. When i try to access the cshtml page it works fine.
Please help me to overcome the issue