Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
HTML
@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 :
HTML
@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:
C#
//
       // GET: /Comment/Create
       [HttpGet]
       [ValidateInput(false)]
       public ActionResult Create(int NewsId)
       {


           return PartialView();
       }

       //
       // POST: /Comment/Create

       [HttpPost]
       [ValidateInput(false)]
       public ActionResult Create(Comments comments)
       {
           //string st = HttpContext.Session["captcha"].ToString();
           //if (st == "1")
           {
               comments.DateCreat = DateTime.Now.ToShortDateString();
               if (ModelState.IsValid)
               {

                   db.Comments.Add(comments);
                   db.SaveChanges();
                   ModelState.Clear();

                   ControllerContext.HttpContext.Response.Redirect(Request.UrlReferrer.ToString());
               }
           }
           //else
           //{
           //    ModelState.AddModelError("Cap", "مقدار با تصویر برابر نیست");

           //}
           return PartialView();
       }

and it is view'command
HTML
@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 :

HTML
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
Posted
Comments
ashok rathod 8-Jul-14 23:51pm    
As you are using MVC, I would suggest please check once again the file path(view) you are going to access has same name as you defined as startpage and you had respective controller with that actionresult in place and having expecting type of argument.

1 solution

hi oh my god
What was a big mistake
This error was due to my [HttpGet] had used
And [HttpPost] did not define
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900