Вы включили макет, но, по вашему мнению, у вас есть весь документ <html>
, и я полагаю, что в конце вы получите очень испорченный HTML.
Вот как может выглядеть ваше представление, если вы не хотите использовать макет:
@{
ViewBag.Title = "Statistics";
// Explicitly specify that we don't use any layout because
// this view already contains the entire html document
Layout = null;
}
<html>
<head>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
</head>
<body>
<h2>
Statistics</h2>
<h2>
What time is it?</h2>
<p>
Show me the time in:<br />
@Ajax.ActionLink("UTC", "GetTime", new { zone = "utc" }, new AjaxOptions { UpdateTargetId = "myResults" })<br />
@Ajax.ActionLink("BST", "GetTime", new { zone = "bst" }, new AjaxOptions { UpdateTargetId = "myResults" })
<br />
@Ajax.ActionLink("MDT", "GetTime", new { zone = "mdt" }, new AjaxOptions { UpdateTargetId = "myResults" })
<br />
</p>
<div id="myResults" style="border: 2px dotted red; padding: .5em;">
Results will appear here
</div>
<p>
This page was generated at @DateTime.UtcNow.ToString("h:MM:ss tt") (UTC)
</p>
</body>
</html>
Единственные скрипты, которые вам нужны - это jquery
и jquery.unobtrusive-ajax
. Также не используйте атрибуты runat="server"
в бритве.
и если вы хотите использовать макет:
@{
ViewBag.Title = "Statistics";
}
<h2>
Statistics</h2>
<h2>
What time is it?</h2>
<p>
Show me the time in:<br />
@Ajax.ActionLink("UTC", "GetTime", new { zone = "utc" }, new AjaxOptions { UpdateTargetId = "myResults" })<br />
@Ajax.ActionLink("BST", "GetTime", new { zone = "bst" }, new AjaxOptions { UpdateTargetId = "myResults" })
<br />
@Ajax.ActionLink("MDT", "GetTime", new { zone = "mdt" }, new AjaxOptions { UpdateTargetId = "myResults" })
<br />
</p>
<div id="myResults" style="border: 2px dotted red; padding: .5em;">
Results will appear here
</div>
<p>
This page was generated at @DateTime.UtcNow.ToString("h:MM:ss tt") (UTC)
</p>
Еще раз не забудьте 2 сценария в вашем макете.
И последнее замечание: по соглашению все действия контроллера должны возвращать ActionResults, поэтому:
public string GetTime(string zone)
{
DateTime time = DateTime.UtcNow.AddHours(offsets[zone]);
return Content(string.Format("<div>The time in {0} is {1:h:MM:ss tt}</div>", zone.ToUpper(), time));
}
Наконец, убедитесь, что вы не используете Microsoft*.js
скрипт на своих страницах. Те устарели.