0

JQueryテンプレート内でRazorを使用する方法はありますか!?!?

<td class="start">{% if (!o.options.autoUpload) { %}
            <button class="btn btn-primary">
                <i class="icon-upload icon-white"></i>
                <span>{%=locale.fileupload.start%}</span>
            </button>
**@Html.LookupValues("Hrm_PeriodStatus_PeriodStatusType",CalendarPeriodFields.PeriodStatusType, "V_PeriodStatusTypeTitle")**   
        {% } %}</td>
     {% } else { %}
        <td colspan="2"></td>
    {% } %}
    <td class="cancel">{% if (!i) { %}
        <button class="btn btn-warning">
            <i class="icon-ban-circle icon-white"></i>
            <span>{%=locale.fileupload.cancel%}</span>
        </button>
    {% } %}</td>

このテンプレート内にドロップダウンを作成したいのですが、プロセスは完全に分離されています!

4

1 に答える 1

0

このjavascriptファイルがサーバー側ハンドラーを介してレンダリングされない限り、javascriptなどの静的ファイル内でサーバー側ヘルパーを使用することはできません。

たとえば、ビューを提供するコントローラーアクションを作成できます。

public class MyTemplatesController: Controller
{
    public ActionResult Index()
    {
        Response.ContentType = "text/javascript";
        return View();
    }
}

次に、テンプレート(~/Views/MyTemplates/Index.cshtml)を含み、サーバー側ヘルパーを使用できる対応するビューを作成できます。

<td class="start">
    {% if (!o.options.autoUpload) { %}
        <button class="btn btn-primary">
            <i class="icon-upload icon-white"></i>
            <span>{%=locale.fileupload.start%}</span>
        </button>
        @Html.LookupValues(
            "Hrm_PeriodStatus_PeriodStatusType",
            CalendarPeriodFields.PeriodStatusType, 
            "V_PeriodStatusTypeTitle"
        )
    {% } %}
</td>
{% } else { %}
    <td colspan="2"></td>
{% } %}
<td class="cancel">
{% if (!i) { %}
   <button class="btn btn-warning">
       <i class="icon-ban-circle icon-white"></i>
       <span>{%=locale.fileupload.cancel%}</span>
   </button>
{% } %}
</td>

次に、このスクリプトを参照できます。

<script id="someTemplate" src="@Url.Action("MyTemplates", "Index")" type="text/x-jquery-tmpl"></script>
于 2013-01-21T12:22:50.043 に答える