开发者

How do I include one page in another with mvc?

I have a view (Show) which is quite long and complex (made up of many partials). It's strongly typed to a viewmodel. I have a delete action which needs to display a view which has "Äre you sure you want to delete?" and a Yes/No button AND the entire Show view.开发者_开发问答 I don't want to copy/paste everything from the Show onto this view...what's the best way of doing this? Do I make the Show a partial (if possible)? Or is there a better way to handle this situation? i.e Delete confirmation showing data from multiple views


I believe that partials can also render partials. If you made your Show a partial, it could be used in both the Show action as well as Delete.


Why not just have your delete page go to the same as your Show page (view), with a parameter to optionally show the "Delete" confirmation/button at the bottom?

For example, the URL would be:

www.sample.com/stuff/delete

You could wire your Delete action into the same view, and in your controller, just render the view, with a property indicating the delete stuff should show:

public ActionResult Delete()
{
    var model = new ShowViewModel();

    model.DoDelete = true;

    return this.View("Show", model);
}

Normally, though, it's best to keep your views separate, and reuse common code using partials. But if 99% of it is one block that is shared, it may be acceptable to go with the above approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜