Take the following script. Notice the string '/Home/Index'. Using T4MVC, is there a way to specify this to get rid of the magic string?
<script type="text/javascript">
$(document).ready(function () {
$dialog = $('#dialog');
$dialog.dialog({
autoOpen: false,
buttons: { },
open: function(event, ui) {
$(this).load("/Home/Index");
}
});
});
</script>
It's this if your view is using Razor
@Url.Action(MVC.Home.Index())
So your script would be
<script type="text/javascript">
$(document).ready(function () {
$dialog = $('#dialog');
$dialog.dialog({
autoOpen: false,
buttons: {},
open: function (event, ui) {
$(this).load("@Url.Action(MVC.Home.Index())");
}
});
});
</script>
If your script is in a separate .js file (not in the Razor view) you can use T4MvcJS to handle that case.
It'll look almost the same to the Skuld's example:
$(this).load(MvcActions.Home.Index());
but it'll be pure Javascript.
(T4MvcJs will generate a js-helper - very similar to the T4MVC)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With