Reputation: 9
I make a customize controller about calendar. But a div required to append to body. I search,but get nothing . The following code what I implement works,but not fine. I figure out that, div should be put to the end of body ,just like jquery $('body').append('div')
But I don't know how to code in MVC helper.
public static MvcHtmlString CalendarTextBox(this HtmlHelper helper, string name, DateTime? value, DateTime start, DateTime max, string nextTriggerId, object htmlAttributes = null)
{
var result = helper.TextBox(name, value, htmlAttributes);
var str = result.ToHtmlString().Replace(@"/>", string.Format(@" mod=""calendar|notice""
mod_notice_tip=""yyyy-mm-dd""
mod_calendar_rangeStart=""{0}""
mod_calendar_rangeEnd=""{1}""
mod_calendar_focusNext=""{2}"" //>", start.ToString("yyyy-MM-dd"), max.ToString("yyyy-MM-dd"), nextTriggerId));
if (null == helper.ViewData["calendar"])
{
str += string.Format(
@"<div style=""HEIGHT: 0px""id=""jsContainer""class=""jsContainer""><div style=""DISPLAY: none""id=""jsHistoryDiv""></div><textarea style=""DISPLAY: none""id=""jsSaveStatus""></textarea><div style=""Z-INDEX: 999; POSITION: absolute; DISPLAY: none; OVERFLOW: hidden""
id=""tuna_alert""></div><div style=""Z-INDEX: 120; POSITION: absolute; VISIBILITY: hidden""
id=""tuna_jmpinfo""></div><div style=""Z-INDEX: 120; POSITION: absolute; DISPLAY: none""id=""tuna_calendar""
class=""tuna_calendar""></div></div><SCRIPT type=text/javascript charset=utf-8 src=""{0}/js/datepicker/tuna_100324_jsLoader.js""></script><script type=""text/javascript"">var JL=new CtripJsLoader();var files=[[""{0}/js/datepicker/tuna_100324_index.js"",""utf-8"",true]];JL.scriptAll(files);</script>",
Define.ASSET_PATH);
helper.ViewData["calendar"] = 1;
}
return MvcHtmlString.Create(str);
}
Upvotes: 1
Views: 1755
Reputation: 237
Inject the $('body').append('div');
line into the generated HTML and nest the statement within a javascript block within the document ready function:
// ...
str += string.Format(
@"<script type=""text/javascript"">$(document).ready(function () {
$('body').append('div'); } </script>");
helper.ViewData["calendar"] = 1;
// ...
Upvotes: 1