一种视图,两种选择

发布于 2024-11-04 11:53:51 字数 237 浏览 0 评论 0原文

我正在建立一个论坛,并且有一个问题页面(包含所有问题)。

进入问题详细信息页面,每个问题都有一个编辑问题链接,并且所有答案都有一个编辑答案链接。

它们之间的区别在于,当我单击问题的编辑时,我希望在文本框中显示我的标题,但是当我单击答案上的编辑时,我希望在标签中显示我的标题。

最佳实践是什么:使用两个模型视图构建不同的视图还是在一个视图中构建?

I am building a forum and I have a question page (having all the question).

Going in the question details page I have an edit question link for each question and I have an edit answer link for all the answers as well.

The difference between them would be when I click the edit for the question I would like to have my title in the text box but when I click edit on the answer I would like to have my title in the label.

What would be the best practice: Build different Views with two Model Views or do it in one View?

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

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

发布评论

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

评论(2

等风也等你 2024-11-11 11:53:51

MVC 的一般指导不考虑业务逻辑。这听起来像是业务逻辑。

当然,如果大多数视图都是通用的,则可以将其分解为它们都使用的部分视图。

General guidance for MVC is no business logic in view. And this sounds like it could be business logic.

Of course if most of the views are common that can be factored out into a partial they both use.

拔了角的鹿 2024-11-11 11:53:51

这可能不是最佳实践,但可能是一个很好的解决方案:

模型:

public partial class QuestionAnswer
{
    public string Question { get; set; }
    public string Answer { get; set; }
    public string DisabledQuestion { get; set; }
}

控制器:

public ActionResult EditQuestion()
{
    DisabledQuestioon = true;
    return View("QuestionAnswer");
}

public ActionResult EditAnswer()
{
    DisabledQuestioon = false;
    return View("QuestionAnswer");
}

视图:

@Html.TextBoxFor(model => model.Question, new { (model.DisabledQuestion ? @readonly = "readonly" : null) })
@Html.TextBoxFor(model => model.Answer)

That might be not the best practice but might be a good solution:

Model:

public partial class QuestionAnswer
{
    public string Question { get; set; }
    public string Answer { get; set; }
    public string DisabledQuestion { get; set; }
}

Controller:

public ActionResult EditQuestion()
{
    DisabledQuestioon = true;
    return View("QuestionAnswer");
}

public ActionResult EditAnswer()
{
    DisabledQuestioon = false;
    return View("QuestionAnswer");
}

View:

@Html.TextBoxFor(model => model.Question, new { (model.DisabledQuestion ? @readonly = "readonly" : null) })
@Html.TextBoxFor(model => model.Answer)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文