ASP.NET MVC3 C# - 并非所有代码路径都会返回值

发布于 2024-11-30 07:32:34 字数 1160 浏览 3 评论 0原文

我快要完成这个循环了!

控制器:

// Hide 'posts'
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Hide (int id)
    {
        var post = db.tb_SH_Forum_Posts.Single(p => p.Post_ID == id);
        post.Private_ID = (post.Private_ID == 1) ? 2 : 1;
        db.SaveChanges();
        RedirectToAction("Details", new { id = post.Thread_ID });
    }

视图:

@foreach
(var post in Model.tb_SH_Forum_Posts.Where(w => w.Private_ID == 1).OrderBy(o =>     o.Post_Date))
{
using (Html.BeginForm("Hide", "Post", new { id = post.Post_ID }))
{   
   <input type="submit" name = "hidePosts" value="Hide" /> 
}

<div class ="post">
<fieldset>
        <p class="post_details">At @post.Post_Date By @(post.Anon == true ? "Anonymous"     : post.Username)          
        </p>
        @post.Post_Desc

</fieldset>
        </div>}

错误:

找不到资源。

描述:HTTP 404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下 URL 并确保拼写正确。

请求的 URL:/Post/Hide/1

我知道 /Post/Hide/1 不存在!我不想这样!它应该重定向到 /Thread/Details/id (因此“帖子”所在的“线程”)

一如既往,非常感谢任何帮助/指导!

I'm almost there with this loop!

Controller:

// Hide 'posts'
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Hide (int id)
    {
        var post = db.tb_SH_Forum_Posts.Single(p => p.Post_ID == id);
        post.Private_ID = (post.Private_ID == 1) ? 2 : 1;
        db.SaveChanges();
        RedirectToAction("Details", new { id = post.Thread_ID });
    }

View:

@foreach
(var post in Model.tb_SH_Forum_Posts.Where(w => w.Private_ID == 1).OrderBy(o =>     o.Post_Date))
{
using (Html.BeginForm("Hide", "Post", new { id = post.Post_ID }))
{   
   <input type="submit" name = "hidePosts" value="Hide" /> 
}

<div class ="post">
<fieldset>
        <p class="post_details">At @post.Post_Date By @(post.Anon == true ? "Anonymous"     : post.Username)          
        </p>
        @post.Post_Desc

</fieldset>
        </div>}

Error:

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: /Post/Hide/1

I know that /Post/Hide/1 doesn't exist! I don't want it to! It's supposed to redirect to /Thread/Details/id (ergo the 'thread' that the 'post' was in)

As always, any help/guidance is MUCH appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜清冷一曲。 2024-12-07 07:32:34
 return RedirectToAction("Details", new { id = post.Thread_ID })
 return RedirectToAction("Details", new { id = post.Thread_ID })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文