1
DatePickerのHTMLExtensionメソッドを作成しました。次のように私は(画像の場所のための太字のテキストを参照)ビューからそれを参照:ASP.NET MVC - IISで実行するとイメージファイルを見つけることができない
<label for="Effective Start Date", class="codeValuesEditLabel"> Effective Start Date (YYYY/MM/DD): </label>
<%= Html.DatePicker("CodeValueNewEditModel_EffectStartDate", "CodeValueNewEditModel.EffectStartDate", "../../Content/images/calendar.gif",
Model.codeValueNewEditModel.EffectStartDate) %>
HTMLExtension方法:
public static string DatePicker(this HtmlHelper helper, string id, string name, **string imageUrl**, object date)
{
StringBuilder html = new StringBuilder();
// Build our base input element
html.Append("<input type=\"text\" id=\"" + id + "\" name=\"" + name + "\"");
// Model Binding Support
if (date != null)
{
string dateValue = String.Empty;
if (date is DateTime? && ((DateTime)date) != DateTime.MinValue)
dateValue = ((DateTime)date).ToString("yyyy/MM/dd");
else if (date is DateTime && (DateTime)date != DateTime.MinValue)
dateValue = ((DateTime)date).ToString("yyyy/MM/dd");
else if (date is string)
dateValue = (string)date;
html.Append(" value=\"" + dateValue + "\"");
}
// We're hard-coding the width here, a better option would be to pass in html attributes and reflect through them
// here (default to 75px width if no style attributes)
html.Append(" style=\"width: 75px;\" />");
// Now we call the datepicker function, passing in our options. Again, a future enhancement would be to
// pass in date options as a list of attributes (min dates, day/month/year formats, etc.)
// If there is no image given, open calendar by clicking on text box
if (imageUrl == null)
{
html.Append("<script type=\"text/javascript\">$(document).ready(function() { $('#" + id + "').datepicker({ dateFormat: 'yy/mm/dd', changeMonth: 'true', changeYear: 'true', duration: 0 }); });");
}
else
{
html.Append("<script type=\"text/javascript\">$(document).ready(function() { $('#" + id + "').datepicker({ dateFormat: 'yy/mm/dd', showOn: 'button', changeMonth: 'true', changeYear: 'true', buttonImage: '" + **imageUrl** + "', duration: 0 }); });");
}
html.Append("</script>");
return html.ToString();
}
IISを実行したときにすべてが開発サーバ上で実行したときに動作しますが、イメージが見つかりません。一般的に私はこれらの問題を解決するために "Url.Content"を使用しますが、私はそれをJavascriptに置くことはできません。誰にも何か提案がありますか?
ルック。それがあなたの問題を解決するのに役立たない場合は、ここに投稿してください。 –
ヘルパーでjavascriptを構築するときに、imageUrlパラメータの前後で 'Url.Content'を使用できないのはなぜですか? –
スクリプトタグを次のように変更しました:buttonImage: '<%= Url.Content(\ "" + imageUrl + "\")%>'そして、ビューを次のパス(imageURL)に渡すように修正しました: "〜/ Content /images/calendar.gif "イメージは開発サーバー上に見つかりません。私が間違っていることを知っていますか? – Jeff