DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
224 stars 79 forks source link

null reference exception #167

Closed Yustie closed 10 years ago

Yustie commented 10 years ago

Hi,

I'm getting this error message at run time:

Unhandled exception at line 6, column 2 in http://localhost:53860/Scripts/TwitterBootstrapMvcJs--3.0.1.js

0x800a138f - JavaScript runtime error: Unable to get property 'setDefaults' of undefined or null reference.

I'm including this file as the last one of all js scripts. What am I doing wrong?

DmitryEfimenko commented 10 years ago

I think you might have a javascript file jquery.validate.js missing.

Yustie commented 10 years ago

You where right, didn't know I needed that one. It's included. But now it gives me this error:

Unhandled exception at line 23, column 4 in http://localhost:53860/Scripts/TwitterBootstrapMvcJs--3.0.1.js

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'typeahead'

Am I missing another script?

DmitryEfimenko commented 10 years ago

I suppose you are missing bootstrap.typeahead.js. Check out docs for typeahead. It's there.

Yustie commented 10 years ago

I have that file referenced. Seemed that I had to clear my cache as well.

But I still don't get it to work. I'm typing but nothing happens. This is what I got:

@Html.Bootstrap().TextBoxFor(x => x.State).TypeAhead(new TypeAhead().Controller("Home").Action("GetCountries"))

I have a breakpoint set in the home controller and I see it's getting there with results. But they are not showed in that textbox control.

DmitryEfimenko commented 10 years ago

please show me html rendered by BMVC code.

Yustie commented 10 years ago

This is it:

<input autocomplete="off" class="form-control" data-minLength="1" data-provide="typeahead" data-url="/Home/GetCountries" id="Country" name="Country" type="text" value="" />

DmitryEfimenko commented 10 years ago

I'm not sure what's wrong. What version of JQuery is referenced?

Yustie commented 10 years ago

<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script> <script src="@Url.Content("~/Scripts/bootstrap.typeahead.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/TwitterBootstrapMvcJs-3.0.1.js")" type="text/javascript"></script>

DmitryEfimenko commented 10 years ago

everything looks right. Please contact me via email.

Yustie commented 10 years ago

I fixed it, the problem was, I was passing a complete Entity Framework object. Instead of just the country name. I did result.Select(x => x.name) in the return new JsonResult() block.

DmitryEfimenko commented 10 years ago

All right, closing the issue.