【问题标题】:mvc advice needed on create/new view that is assigned to a model?分配给模型的创建/新视图需要 mvc 建议吗?
【发布时间】:2011-11-26 13:37:46
【问题描述】:

我对设置 mvc 很陌生,请耐心等待.. 所以我有这两个模型

public class Promoter
 {
    public int Id {get; set;}
    public string Name {get;set;}

    public ICollection<Event> AllEvents {get;set;}
 }

public class Event
 {
    public int Id {get;set;}
    public string Name {get;set;}
    public date Date {get;set;}
    public int PromoterId {get; set;}

    public virtual Promoter Promoter {get;set;}
 }

我有一个控制器事件

public class EventsController : Controller
{
   public ActionResult New()
   {
        return View()
   }
   [HttpPost]
   public ActionResult New(Model model)
   {
       // do stuff to save the new Event related to Promotion
   }
}

所以我的问题是,在 New Action 上,我如何确保 New View 能够拥有一个标识符相关?我正在考虑 hiddenfor 具有 PromotionId 以便在调用 Post 时该 ID 会在那里,但是当我调用 New 时我将不得不传递促销员 ID行动? 还是您认为我应该在访问该页面之前将促销员详细信息存储在 cookie 中? 需要注意的另一件事是,用户将通过身份验证并且需要登录才能访问 Promotion 控制器(此线程中未显示),然后在该控制器上用户可以转到说 Event Controller 会有新的 Action...

我希望这是有道理的。 需要一些建议,想法/想法非常感谢。

谢谢,

G

【问题讨论】:

    标签: c# asp.net-mvc model-view-controller model


    【解决方案1】:

    您的想法是正确的,您需要将promotionId 传递给新动作,而动作需要将其传递给视图。也可以通过cookie,但我觉得action参数更方便——因为action参数会在url中,所以用户甚至可以收藏它,发送给另一个用户等等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 2020-10-29
      相关资源
      最近更新 更多