Using MVCt4 inside Javascript - t4mvc

I have recently become a T4MVC fanatic and now I seem incapable of using visual strings in my MVC3 projects. I am currently trying to use an T4MVC link to a script file inside a JavaScript function but it appears that I'm either doing it wrong or it's not possible. The code follows. Any help would be appreciated.
<script type="text/javascript">
$(function () {
if (!Modernizr.inputtypes.range) {
$.getScript(#Links.Scripts.modernizr_1_7_min_js, function(){
$("input[type='range']").range();
});
}
});
</script>
EDIT:
Sorry, there is no issue with T4MVC in JavaScript. Looking at the page source, the link text is generated properly.

Sorry. This ended up being a non-issue. There is no issue with using T4MVC in Javascript. I guess I was thrown off because VS does not provide intellisence for T4MVC while editing JS. Thanks for following up David.

Related

How can I get IntelliSense to work inside of a script tag for Razor helpers?

IntelliSense does not work in Visual Studio 2010 if you are inside of a <script> tag and try to use #Html.. Anyone know how to enable or fix that?
Please note: This is not for javascript, jQuery, or similar, IntelliSense-enabling which is possible.
This appears to be a bug/complexity resulting from hosting JavaScript inside the HTML editor: http://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/2706979-improve-the-razor-intellisense-inside-script-block
It doesn't look like it will be resolved anytime soon.
Just a quick suggestion, separate JavaScript and Razor like I described here:
https://stackoverflow.com/a/11109799/538387

YUI on Windows 8 Metro App: YUI is not recognized

I am trying to create a Hello World JS Metro app on Visual Studio 2011, using YUI3.
I´ve grabbed a local copy of YUI, added to a subfolder in the solution, and added a reference to yui-min.js on my default.html page:
<!-- TodoJS references -->
<link href="/css/default.css" rel="stylesheet">
<script src="/js/default.js"></script>
<script src="js/yui/build/yui/yui.js"></script>
and then at the bottom of the page I´ve added the following code:
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
YUI().use("event", function () {
//some code will go here..
});
}, false);
</script>
When I run the code, I get a null ref error on YUI(). I do get intelissense working in Visual Studio (e.g YUI().add), so the reference seems to be OK, but YUI is not found on run time. Any tips?
I would try the steps outlined in How To: Create a Windows 8 Metro App with JS and YUI 3
I take it that you've got the issue fixed. However if you'd like to use the YUI components such as "calendar", "tabview" etc, you'll have to modify a few files that include innerHTML calls and wrap the added html content with toStaticHTML.
There were only a couple of files(dom-base.js, yui.js) that needed to be modified and most of the components worked fine(including the "datatable" and "charts" widgets), with the exception of the rich text editor. The nice thing about YUI is that it supports touch gestures for a majority of the components, for example panning "datatable" works correctly.

#Url.Content not pointing to correct path in a new MVC project

I'm having trouble figuring out why when I create a new MVC 3 application the jQuery intellisence is not working until I alter the script tag in my _Layout page. According to a tutorial I watched, as long as I placed the vsdoc file in my scripts folder, I should have jQuery intellisense but that is not the case, at least thats not happening for me. After creating a new project, here is what the script tag looks like in my _Layout.cshtml page:
<script src="#Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
I have included the vsdoc file in my Scripts folder but I do not have jQuery intellisense. If I do a view sorce on the page here is what I see:
<script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
It doesn't look as if the path is correctly resolved.
So I then delete this tag and replace it by dragging and dropping the file to the page and end up with this:
<script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
Now I get jQuery intellisense. So why do I have to make these changes befeore I get intellisense? Is this something that others have experienced or am I possibly doing something wrong? It seems like the #Url.Content functionality is broke and leads me to wonder if maybe I will have problems with it for other uses like placing images on a form.
As far as I am aware, your vsdoc.js script cannot just exist in the scripts folder. It has to be referenced in every view that will use it.
You should reference it like this:
#if (false) {
<script src="../../Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript"></script>
}
Note: Check the version of the file that you reference is correct.
The if statement will prevent the browser from actually downloading the file.

EF 4.0 - Save creates duplicates in TEST environment, but not in DEV

FINAL EDIT If you are looking at this question, please see the answer I posted below. The original problem was not with EF, it was with my JQuery implementation.
EDIT: I have confirmed that this is only happening in IE (specifically IE 7). I don't see the same behavior in Chrome. I haven't tested Firefox yet, but we don't support FF in our environment, so I'm not as worried about it.)
Before I post a bunch of code, I just wanted to put this out there to see if anyone else has ever experienced anything similar, and if so, what their culprit was.
I have code in an MVC project that creates a new entity. The code works as expected in my local environment. However, when I push the code out to our test server environment, the same code creates two records upon save.
I have verified that the database schemas are identical, so I have eliminated that as a possible cause.
Has anyone else ever experienced anything like this? If so, what did you do to fix the problem?
Thanks
I finally tracked the issue down to a bug in some javascript. The problem had nothing to do with Entity Framework or MVC. I have some jQuery code that helps me add icons to submit buttons, and in IE it was causing the submit to happen twice.
In case anyone is interested, here is the offending code:
$('input[type="submit"]').each(function () {
$(this).hide().after('<button>').next().button({
icons: { primary: $(this).attr('icon') },
label: $(this).val()
}).click(function (event) {
event.preventDefault();
$(this).prev().click();
return false;
});
});
This caused no problems in Chrome, but in IE the submit buttons were firing twice. To fix it, i added onclick="return false;" to my input tags, and the problem went away.

Visual Studio 10, JavaScript intellisense inside javascript.js file, and where is the MicrosoftAjax-vsdoc.js

I can get javascript intellisense going from and aspx or master page ie
<script src="../../Scripts/jquery-1.4.1-vsdoc.js"type="text/javascript"></script>
<script type="text/javascript">
$.isFunction(
</script>
gives me a drop down in vs2010.
I do all(most) of my js coding inside a js file.
How do I get intellisense drop downs inside js files ?
Also, is there a vsdoc for ms ajax (MicrosoftAjax-vsdoc.js) ?
At the top of your .js file add this:
/// <reference path="jquery-1.4.1.js" />
Or make the path relative, if it's not in the same directory, it'll look for the jquery-1.4.1-vsdoc.js when grabbing it for intellisense, any file you reference like this it'll look for the -vsdoc version if available. As a side note, jQuery 1.4.2 has additional bug fixes you should consider upgrading :)

Resources