using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Conference.Models;
namespace Conference.Controllers
{
public class PostController : Controller
{
private ConferenceContext db = new ConferenceContext();
//
// GET: /Post/
public ActionResult Index(int id = 0)
{
var postList = db.Posts.Where(i => i.PostedToID == id);
return View(postList.ToList());
}
答案 0 :(得分:1)
您的网址必须是Post / Index /。
另一种可能性是使用路由(将其添加到RouteConfig.cs):
routes.MapPageRoute("Post",
"Post/{id}/",
new { controller = "Post", action = "Index", id = ""});
答案 1 :(得分:1)
默认路由(App_start / RouteConfig.cs)是
Controller / Action / id,其中id在路由
中是可选的你的网址应该是 http:// ... / Post / Index / 2
视图名称应为索引并位于文件夹
中Views/Post
或
Views/Shared