View Full Version : عدم load تقویم فارسی در Layout اصلی MVC
  
jaykob
شنبه 29 شهریور 1393, 20:50 عصر
سلام 
من از پلاگین زیر برای تقویم فارسی استفاده می کنم 
https://github.com/behzadi/persianDatepicker
در صفحه معمولی هیچ مشکلی نداره اما زمانی یک View می سازم که از Layout پیش فرض mvc ارث برده باشد کار نمی کنه فراخوان js ها و css هارو هم خیلی تغییر دادم اما درست نشد
ممنون می شم راهنمایی کنید
مهدی کرامتی
شنبه 29 شهریور 1393, 23:46 عصر
کدی که در Layout و View قرار دادید رو بنویسید.
jaykob
یک شنبه 30 شهریور 1393, 13:23 عصر
خیلی ممنون
کد Layout من :
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - </title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <link href="~/Content/css/bootstrap-rtl.css" rel="stylesheet" />
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("صفحه اصلی", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("کارهای من", "Index", "Job")</li>
                    <li>@Html.ActionLink("گزارش کاری", "Index", "Report")</li>
                    <li>@Html.ActionLink("مرخصی", "Index", "Leave")</li>
                    <li>@Html.ActionLink("پیام خصوصی", "Index", "Message")</li>
                    <li>@Html.ActionLink("دفترچه یادداشت", "Index", "Note")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>© @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>
و کد View من که می خوام datepiker به فیلد date من متصل شود :
@using System.Web.UI.WebControls
@model MySystem.Web.ViewModel.AccountingViewModel.InsertA ccountingViewModel
@{
    ViewBag.Title = "ثبت سند ";
}
<link type="text/css" rel="stylesheet" href="/Content/persianDatepicker-default.css" />
<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/Scripts/persianDatepicker.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#Date").persianDatepicker();
    });
</script>
<h2>Index</h2>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="form-horizontal">
        <h4>ثبت سند </h4>
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control", style = "width:300px !important" } })
                @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Comment, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.Comment, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Comment, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("Type", new List<SelectListItem>
                {
                   new SelectListItem {Text = "پرداختی",Value = "پرداختی" },
                   new SelectListItem{Text = "دریافتی",Value = "دریافتی"}
                }, "انتخاب کنید", htmlAttributes: new { @class = "form-control", style = "width:300px !important" })
                @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Date)
                @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="ثبت" class="btn btn-default" style="width:80px !important" />
            </div>
        </div>
    </div>
}
کارهایی که من کردم :
1 - کد های js و css بالا رو بردم داخل Layout زیر تگ title گذاشتم که نشد
2 - همون کد هارو داخل View خودش همه جا گذاشتم ( بالا ، پایین ) اما نشد
3 - کد ها رو داخل Bundler معرفی کردم بازم نشد . 
=> همین کد ها رو داخل یک view که از layout ارث نبرده باشه می گذارم درست کار می کنه و مشکلی نیست کدش رو هم در زیر قرار می دم :
@model Automation.Web.ViewModel.AccountingViewModel.Inser tAccountingViewModel
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>datetest</title>
    <link type="text/css" rel="stylesheet" href="/Content/persianDatepicker-default.css" />
    <script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/Scripts/persianDatepicker.min.js"></script>
    <script type="text/javascript">
    $(function () {
        $("#Date").persianDatepicker();
    });
    </script>
</head>
<body>
    @using (Html.BeginForm()) 
    {
        @Html.AntiForgeryToken()
        
        <div class="form-horizontal">
            <h4>InsertAccountingViewModel</h4>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Comment, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Comment, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Comment, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Type, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.UserId, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
    
    <div>
        @Html.ActionLink("Back to List", "Index")
    </div>
</body>
</html>
ممنون می شم راهنمایی کنید چون فکر کنم داخل هر پروژه ای این داستان برام پیش بیاد باید حل بشه ...
تشکر
gama_slv
سه شنبه 01 مهر 1393, 12:08 عصر
من در پروژه جدیدی که ساختم این مشکل برام پیش امده قبلا چنین مشکلی نداشتم . هر پروژه جدید هم میسازم همین مشکل هست؟؟
البته من از Datepicker هاشمی نژاد استفاده کردم
jaykob
سه شنبه 01 مهر 1393, 13:25 عصر
من همچنان مشکلم هست . لطفا راهنمایی کنید
با تشکر
مهدی کرامتی
سه شنبه 01 مهر 1393, 13:37 عصر
پلاگین هاشمی نژاد به jQuery UI هم نیاز دارد و شما در صحفات تان به آن رفرنس نداده اید.
gama_slv
سه شنبه 01 مهر 1393, 13:57 عصر
در Layout
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")"></script><script type="text/javascript" src="@Url.Content("~/Scripts/jquery.ui.core.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.ui.datepicker-cc.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/calendar.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.ui.datepicker-cc-ar.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.ui.datepicker-cc-fa.js")"></script>
<link href="@Url.Content("~/Content/jquery-ui-1.8.14.css")" rel="stylesheet" type="text/css" />
اسکریپت در خود view به خاطر عمل نکردن سلکتور 
<script type="text/javascript">    $(document).ready(function () {
        $('#BirthDate').datepicker();
      
    });
</script>
در Layout
 <script type="text/javascript">        $(document).ready(function () {
            $("[id*=Date]").each(function () {
                $(this).datepicker({
                    dateFormat: 'yy/mm/dd',
                    showOn: 'button',
                    buttonImage: '/Content/calendar.gif',
                    buttonImageOnly: true,
                    showButtonPanel: true
                });
            });
        });
    </script>
 در هیچ کدوم از این دو حالت عمل نکرد مجبور شدم رفرنس ها رو داخل خود view بدم تا عمل کنه
gama_slv
چهارشنبه 02 مهر 1393, 11:38 صبح
مشکل حل شد :متعجب:
باید تمام رفرنس ها رو در داخل BundleConfig.cs پروژه اضافه کرد  اسکریپت رو در layout نوشت
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(                     "~/Scripts/bootstrap.rtl.js",
                    "~/Scripts/jquery-1.6.2.min.js",
                    "~/Scripts/jquery.ui.core.js",
                    "~/Scripts/jquery.ui.datepicker-cc.js",
                    "~/Scripts/calendar.js",
                    "~/Scripts/jquery.ui.datepicker-cc-ar.js",
                    "~/Scripts/jquery.ui.datepicker-cc-fa.js",
                    "~/Scripts/respond.js"));
            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.rtl.css",
                    "~/Content/jquery-ui-1.8.14.css",
                     "~/Content/site.css"));
<script type="text/javascript">    $(document).ready(function () {
        $("[id*=Date]").datepicker();
    });
</script>
maryam145
یک شنبه 24 مرداد 1395, 16:00 عصر
سلام خسته نباشین من این پلاگین و نصب کردم و تو MVC اضافه کردم ولی در  هنگام اجرا تو صفحه پایین تکس قرار نمیگیره بیشتر با نمایشش مشکل دارم اینم کدها :
@model RequestFormMVC.Models.DomainModels.Request
@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
<div class="container">
    <div class="row">
        <div class="col-lg-5">
            <h3 class="page-header">فرم درخواست خدمات کامپیوتری</h3>
            <br />
        </div>
        <div class="col-lg-5"></div>
    </div>
    <div class="row">
        <div class="col-lg-5">
            @using (Ajax.BeginForm("Register", "Home", new AjaxOptions { HttpMethod = "Post", Url = "/Home/Register" }))
            {
                Html.EnableClientValidation(false);
                <div class="form-horizontal">
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                    <div class="controls">
                        <div class="form-group">
                            @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-4" })
                            <div class="col-md-8">
                                @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                    <div class="controls">
                       
                            <div class="form-group">
                                @Html.LabelFor(model => model.DateTime, htmlAttributes: new { @class = "control-label col-md-4" })
                                <div class="col-md-8">
                                    @Html.EditorFor(model => model.DateTime, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.DateTime, "", new { @class = "text-danger" })
                                    <div>
                                       
                                         @section styles {
                                            <link href="~/Scripts/PersianDateTimePicker/jquery-ui-datetimepicker.min.css" rel="stylesheet" />
                                        }
                                        @section scripts {
                                            <script src="~/Scripts/PersianDateTimePicker/jquery-ui-datetimepicker.min.js"></script>
                                            <script>
                                                $(function(){
                                                    $("#DateTime").datepicker();
                                                });
                                            </script>
                                        }
                                    </div>
                                </div>
                            </div>
                        
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.RequestName, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            @Html.EditorFor(model => model.RequestName, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model => model.RequestName, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.VahedName, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            @Html.EditorFor(model => model.VahedName, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model => model.VahedName, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.BugType, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            @Html.EditorFor(model => model.BugType, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model => model.BugType, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Information, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            <div class="checkbox">
                                @Html.EditorFor(model => model.Information)
                                @Html.ValidationMessageFor(model => model.Information, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Statuse, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            <div class="checkbox">
                                @Html.EditorFor(model => model.Statuse)
                                @Html.ValidationMessageFor(model => model.Statuse, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-10">
                            <input type="submit" value="Create" class="btn btn-default" />
                        </div>
                    </div>
                </div>
            }
        </div>
        <div class="col-lg-7"></div>
    </div>
</div>
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.