Has T4MVC is not extensible to external JavaScript file, I would like to find the best way for manage "Magic Strings" like a Controller/Action value in a JQuery .load() method.
I want to minimize the risk of the change of an Action to provoque an error in the application. I know that I can compile the Views with Visual Studio to find client side errors, but not in JS external files.
I found some solutions like include a View as a javascript file type so I can use T4MVC and detect Views compilaion errors, but this approach makes a server unnecessary request and if it was JS it would be cached at the client side.
I'm thinking about a constant JS file, or in the limit, a constant View file with T4MVC params method.
Any better ideia?
I leave here a sample:
<script type="text/javascript">
$(function () {
$('#Category_Id')
.cascade(
{
url: '@Url.Action(MVC.Ad.ListCategoryTypeByCategory())',
paramName: '@MVC.Ad.ListCategoryTypeByCategoryParams.categoryId',
firstOption: '@HeelpResources.DropdownlistCategoryTypeFirstRecord',
childSelect: $('#CategoryType_Id')
})
.cascade(
{
url: '@Url.Action(MVC.Ad.ListMakeByCategory())',
paramName: '@MVC.Ad.ListMakeByCategoryParams.categoryId',
firstOption: '@HeelpResources.DropdownlistMakeFirstRecord',
childSelect: $('#Make_Id')
});
$('#Make_Id').cascade({
url: '@Url.Action(MVC.Ad.ListModelByMake())',
paramName: '@MVC.Ad.ListModelByMakeParams.makeId',
firstOption: '@HeelpResources.DropdownlistModelFirstRecord',
childSelect: $('#Model_Id')
});
});
</script>
How can I avoid "Magic Strings" if I want to put this code in a JS external file?
Thanks.