我是靠谱客的博主 苗条发箍,最近开发中收集的这篇文章主要介绍.net mvc 返回html,asp.net mvc 4 - Razor MVC return HTML - Stack Overflow,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I tried to research a bit, but has not found a proper solution to this.

What I'm trying to do is to have a HTML.Action in a page like so

Html.Action("Calendar", "GlobalShared")

Inside the action "Calendar", I need to return the result of the html of the traditional calendar control

public ActionResult Calendar(

String ID,

String CssClass,

int CellSpacing,

int CellPadding,

String BorderWidth,

String ShowGridLines,

String ShowTitle,

String DayNameFormat

)

{

System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();

cal.ID = "MyCalendar";

cal.CssClass = "month-view";

cal.CellSpacing = 0;

cal.CellPadding = -1;

cal.BorderWidth = 0;

cal.ShowGridLines = false;

cal.ShowTitle = false;

cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;

}

How can I do this? Btw, I use HTML.Action is because I read that it returns a html string, is that correct or should I be doing some other ways?

Thanks

Edit. Before I attempted this in a controller, I tried the following code in a view .cshtml and it works, but I prefer to move the code into a controller

@{

System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();

cal.ID = "MyCalendar";

cal.CssClass = "month-view";

cal.CellSpacing = 0;

cal.CellPadding = -1;

cal.BorderWidth = 0;

cal.ShowGridLines = false;

cal.ShowTitle = false;

cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;

cal.RenderControl(new HtmlTextWriter(Html.ViewContext.Writer));

}

Edit #2. The reason I want to use that in a controller is because if in the future, i want to hook up an event say "DayRender", I can do it in the controller. I can not do the same in a view without polluting the view page.

最后

以上就是苗条发箍为你收集整理的.net mvc 返回html,asp.net mvc 4 - Razor MVC return HTML - Stack Overflow的全部内容,希望文章能够帮你解决.net mvc 返回html,asp.net mvc 4 - Razor MVC return HTML - Stack Overflow所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部