Saturday, May 2, 2009 10:03 AM
Kazi Manzur Rashid
Script and CSS Management in ASP.NET MVC – Part 2
My last post on Script and CSS Management in ASP.NET MVC has well accepted by the community and I have got few valuable suggestions, specially from Jake Scott. Beside those, there are one more awkward things I found while working with the Fluent html version which makes me to change few public signatures. Lets see the issue that I am talking about, in the initial version when you want to add multiple script lines, you have to do:
Did you get the issue, yes for formatting I have to add the \r\n at the end of each statement and enclose the whole thing in a “”, a better version would be:
Render() method instead of <%= like the previous version. A complete example of the previous version’s master page would be:
alert('Cleanup for master page.');
response.Flush() in it is, it is not possible to modify the ASP.NET Response header later on in that request. But I don’t think modifying the response header is not all required in our regular scenarios. Next, in the previous version I was using an implicit operator to convert the helper to string which no longer works when using the lambda in view, that is why it is required to call the
Render() where you want to dump the output.
The next two changes does not have any impact on the public signatures, First the file caching, although the cache duration that is specified in the web.config applies to the http response header nothing to do with the server side caching but in this version, to make the development life easier, the server side caching is also depends upon this value (otherwise we have to compile the project each time we make a change in the script/css file), if you want to disable caching in server side just set this value to 0 (zero).
And the last one is adding an overloaded extension method for
UrlHelper, as Jake mentioned he wants to use separate handlers for css and js files, with the overloaded version now you will be able specify the handler when mentioning the asset.
Download: Full Source