开发者

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

开发者 https://www.devze.com 2023-03-08 12:23 出处:网络
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 datepic

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

精彩评论

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

关注公众号