开发者

How to handle Relative Paths in jQuery and MVC, e.g. DatePicker

I have an MVC3 application, I know that for relative paths, I can use Url.Content in my .aspx Views.

However, how do I do something similar in jQuery? The one I'm looking at is the jquery-ui datepicker, e.g. I have the following EditorTemplate for my datetimem DateTime.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %> 
    <%: Html.TextBox("", this.Model.ToString("MM/dd/yyyy"), new { @class="datepicker"}) %> 

    <script type="text/javascript">

    $(document).ready(function () {
        $(".datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'mm/dd/yy', 
            gotoCurrent: true, 
            showOn: 'button',
            buttonImageOnly: true,
            buttonImage: '../../../Content/images/calendar.png'  //开发者_如何学编程 WHAT DO I PUT HERE?
        });

    });   
    </script> 

Thanks,


Why do you think this is not the answer?

<%= Url.Content("/Content/images/calendar.png") %>


You can simply use

<script type="text/javascript">
$(document).ready(function () {
 $(".datepicker").datepicker({
   changeMonth: true,
   changeYear: true,
   dateFormat: 'mm/dd/yy',
   gotoCurrent: true,
   showOn: 'button',
   buttonImageOnly: true,
   buttonImage: '@Url.Content("~/Content/images/calendar.png")'
 });
});   
</script> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜