ASP.NET MVC3 C# - 并非所有代码路径都会返回值
我快要完成这个循环了!
控制器:
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)