3

I'm new to shieldui js and asp.net mvc and I'm doing some examples for a train. I have no problem including the js in a html file but I'm struggling to include it in asp.net mvc. Lets say i have jquery and shield ui in Scripts folder. I did reference Shield.Mvc.UI but I still cant access them via @(Html.XXXX).

Lets say i want to create ShieldCalendar using View.cshtml. The example is:

<div class="container">
@(Html.ShieldCalendar()
    .Name("calendar")
    .HtmlAttribute("class", "calendar")
    .Min(new DateTime(2009, 2, 23))
    .Max(new DateTime(2039, 3, 1))
    .Value(DateTime.Now)
    .Footer(fb => fb.Enabled(true).FooterTemlpate("{0:dd.MM.yy}")))

I'm a beginner and I may miss something fundamental for asp.net MVC.

jrbedard
  • 3,662
  • 5
  • 30
  • 34
Expressingx
  • 1,480
  • 1
  • 14
  • 39

1 Answers1

1

Later findings: it looks like some time ago there weren't html helper extension methods for that. Are you sure you have something like that?

Question reference: shield ui chart: generate series dynamically? (where op is saying that he wrote a custom html helper for .net mvc)

Html helpers reference: http://www.tutorialsteacher.com/mvc/html-helpers

Are you sure you have html helpers in Shield.Web.UI namespace? (see this question too: Referencing the Shield UI ASP.NET MVC javascript modules)

1st approach

You can create a bundle with those two javascript files for now.

Open the App_Start\BundleConfig.cs, there you will have a RegisterBundles method where you can create a bundle with those two files.

 public static void RegisterBundles(BundleCollection bundles)
 {
     bundles.Add(new ScriptBundle("~/bundles/jqueryand")
              .Include("~/Scripts/jquery-3.1.1.js"))
              .Include("~/Scripts/shieldui.js"); 
              // i don't know exactly the name of the library

 }

And in your Global.asax.cs, you need to register this bundle:

In Application_Start method, add the following line:

  BundleConfig.RegisterBundles(BundleTable.Bundles);

Then in your _Layout or your more specific view, you'll have to add @Scripts.Render("~/bundles/jquery")

More about this approach here: https://www.asp.net/mvc/overview/performance/bundling-and-minification

And here: How do I add BundleConfig.cs to my project? (probably this question is very useful)

2nd approach

Use something like RequireJs for .NET, which will bring some features to your application, but will also add some complexity.

See my answer for the question below:

RequireJS - ASP.NET MVC Bundle Script

About this part of your problem:

but I still cant access them via @(Html.XXXX).

Maybe your intellisense is broken, you can give it a try after you add the script to the page/layout and after you make sure that you have

@using Shield.Web.UI

for your page/layout.

Community
  • 1
  • 1
Razvan Dumitru
  • 11,815
  • 5
  • 34
  • 54
  • If you have any more questions, please reply to this thread. Maybe it's better to come back with some exceptions if you're facing some. – Razvan Dumitru Oct 11 '16 at 19:11