I have created a Helper method in MVC3 Razor project as(Helpers.cshtml)
@helper Link(string fileName, UrlHelper url){
<link href="@url.Content("~/Content/" + fileName)"
rel="stylesheet" type="text/css" />
}
But i get a warning tooltip "Element link cannot be nested within element 'link'".
I found similar type of question on Asp.net Error when using link href inside my ContentPlaceHolder
Do we have a solution for this.
Keep in mind that you should only have <link>
tags in the <head>
and not the <body>
. The tooling is unable to confirm from where you'll call this helper, so it barks.
You can verify that this is what's going on by temporarily wrapping the helper in a valid skeleton of markup as below. The warning should go away. You can then confirm the negative case by changing link
to some made-up tag like foo
, or by removing the title
, and watch those errors then appear. You should then be comfortable that as long as you only call your helper from inside <head>
sections, your resulting link
markup is ok.
<html>
<head>
@helper Link(string fileName, UrlHelper url){
<link href="@url.Content("~/Content/" + fileName)" rel="stylesheet" type="text/css" />
}
<title>Foo</title>
</head>
<body></body>
</html>
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