[英]Can I load a javascript file with a partialView in asp.net-mvc?
[英].net mvc load partialview that contains jquery
嗨,我是mvc和Web開發的新手。 我想做這樣的事情
然后,當您單擊編輯時,頁面將加載類似內容。
我正在使用ajax來執行此操作,但是問題是,當我單擊編輯ajax時,請勿使用我的任何腳本,這意味着日期時間選擇器腳本無法正常工作,或者是其他任何javascript。
小米代碼是這樣的
我的主要觀點:
<div id="Estudiantes del tutor">
</br>
<table style="margin-left:auto; margin-right:auto;">
<tr>
<th>Código</th>
<th>Estudiante</th>
<th></th>
</tr>
<% foreach (var item in Model.Hijos) { %>
<tr>
<td>
<%: Html.Encode(item.PersonaNaturalId.ToString("D8")) %>
</td>
<td>
<%: Html.Encode(item.Nombre +" "+item.ApellidoPaterno+ " "+ item.ApellidoMaterno) %>
</td>
<td>
<%: Html.ActionLink("Editar", "EditarEstudiante", new { tutorId = Model.TutorBE.PersonaNaturalId ,estudianteId = item.PersonaNaturalId }) %>
|
<%: Ajax.ActionLink("Editar", "EditarEstudiante", new { tutorId = Model.TutorBE.PersonaNaturalId ,estudianteId = item.PersonaNaturalId }, new AjaxOptions { UpdateTargetId = "DatosEstudiante"})%>
</td>
</tr>
<% } %>
</table>
</div>
<br/>
<br/>
<br/>
<div id="DatosEstudiante">
</div>
我的局部視圖如下所示:
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/SiteHeinrich.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.8.custom.min.js" type="text/javascript"></script>
<link href="../../Content/blitzer/jquery-ui-1.8.8.custom.css" rel="stylesheet" type="text/css" />
<link href="../../Content/VocacionalSite.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.debug.js" type="text/javascript"></script>
<br /> <%= Html.ValidationSummary("Por favor corrija los errores e intente de nuevo.")%> <%using (Html.BeginForm()) { %> <%: Html.ValidationSummary(true) %> <div id="DatosGenerales">
<fieldset style="margin-left: auto; margin-right: auto;">
<legend>Datos generales del estudiante</legend>
<div id="Nombres del estudiante">
<div id="Nombre" style="float: left; margin-left: auto; margin-right: auto; width: 250px;">
<%: Html.Label("Nombres: ") %>
<br />
<%: Html.TextBox("Nombres", Model.Estudiante.Nombre, Model.Estudiante.Nombre != null ? new {@readonly ="readonly"} : null )%>
<%: Html.ValidationMessage("Nombres","*") %>
</div>
<div id="ApellidoPaterno" style="float: left; margin-left: auto; margin-right: auto;
width: 250px;">
<%: Html.Label("Apellido paterno: ") %>
<br />
<%: Html.TextBox("ApellidoPaterno", Model.Estudiante.ApellidoPaterno, Model.Estudiante.ApellidoPaterno != null ? new { @readonly = "readonly" } : null)%>
<%: Html.ValidationMessage("ApellidoPaterno","*")%>
</div>
<div id="ApellidoMaterno" style="float: left; margin-left: auto; margin-right: auto;
width: 250px;">
<%: Html.Label("Apellido materno: ") %>
<br />
<%: Html.TextBox("ApellidoMaterno", Model.Estudiante.ApellidoMaterno, Model.Estudiante.ApellidoMaterno != null ? new { @readonly = "readonly" } : null)%>
<%: Html.ValidationMessage("ApellidoMaterno", "*")%>
</div>
</div>
<br />
<div id="Otros datos generales" style="clear: both;">
<br />
<script>
$(function () {
$("#datepicker").datepicker();
}); </script>
<div class="demo">
<p>Date: <input type="text" id="datepicker"></p>
</div><!-- End demo -->
<div class="demo-description" style="display: none; "> <p>The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.</p> </div><!-- End demo-description -->
</div>
</fieldset> </div>
我將使用jQuery的ready()函數來運行您的腳本。
所以把它從你的局部視圖中拉出來
<script>
$(function ()
{
$("#datepicker").datepicker();
});
</script>
並將其添加到您的主要視圖。 它將在頁面加載后運行。
<script type="text/javascript">
$(document).ready(function ()
{
$("#datepicker").datepicker();
});
</script>
jQuery的document.ready僅觸發一次。 DOM准備就緒后。 因此,您的所有腳本均不會執行。 您可以看看使用livequery之類的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.