有没有办法在asp.net mvc5中公开声明或存储自定义助手?

时间:2016-03-31 02:44:37

标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor

我在ASP.NET MVC 5中创建了一个自定义帮助程序。以下是代码:

Razor语法:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Normal)
    UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Highlighted)

    return true
}

应用帮助:

@ListCountries(ViewBag.Countries,ViewBag.Selected)

这是我控制器中的代码:

@helper ListCountries(string[] items, string selected)
{
    <div class="form-group">
        <select class="form-control">
            @foreach (string str in items)
            {
                if (@str == selected)
                {
                    <option selected="selected">@str</option>
                }
                else
                {
                    <option>@str</option>
                }
            }

        </select>
    </div>
}

我需要的是,我想将上面给出的帮助声明(Razor语法)存储在像.js或.css文件这样的公共位置,以便可以从任何页面引用它。有什么想法吗?

  • Sarin Gopalan

0 个答案:

没有答案