Hi im trying to place a link file in the head from a partial view or a controller (mvc) but cant figure out or find any good mvc 2 example, anybody have an idea?
I tried this Comment made by Jim Tollan
It renders the following for me in the body, im not sure if this is any good?
<script type='text/javascript'>
$(function(){
$('head').prepend('<link rel="canonical" href="/product/productname/productid"></link>');
});
</script>
I would appreciate any help i could get on this im scratching my head on this issue all day long now.
EDIT
this is my current code(this is only mockup code to replicate my real scenario)
on the index page
head content
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
<%: ViewData["Message"] %>
</asp:Content>
body
<div id="container">
empty
</div>
<a href="#" class="click-me">Click me</a>
controller actions
public ActionResult Index()
{
ViewData["Message"] = "this is";
return View();
}
[HttpPost]
public PartialViewResult Index(string value)
{
ViewData["Message"] = "this is not";
return PartialView("_homePartial");
}
jquery
$(".click-me").click(function () {
$.post("/Home/Index", function (data) { $('#container').html(data); }, "html");
and thats it, its obvious the viewdata is set in the post action in the controller but its not set after that, thats why i need a jquery solution or a way to set the head content in the parialview. });