[英]How to append Html.Action to view by using javascript
我试图通过单击添加新按钮来添加新行。 该行包含在下面
<div class="col-sm-12" id="totalRow" cnt="1">
<div class="col-sm-6" style="margin-top: 10px; float: left; padding-left: 0;">
<label for="reg_input">Masrafın Türü</label>
<select id="s2_basic_masrafbutce" name="masrafTuruId">
<option value=""></option>
<optgroup label="Masraf Türleri">
@Html.Action("_MasrafTurleriniGetir", "Ortak", new { ID = 0 })
</optgroup>
</select>
</div>
<div class="col-sm-3" style="margin-top: 10px; float: right; padding-right: 0px;">
<label for="reg_input">Masrafın Tutarı</label>
<input type="text" id="@Html.IdFor(x => x.tutar)" class="form-control" name="tutar">
</div>
<div class="col-sm-3" style="padding-right: 0; margin-top: 10px; float: right">
<label for="reg_input">Fiş No</label>
<input type="text" id="@Html.IdFor(x => x.fis_no)" class="form-control" name="fis_no">
</div>
<div class="col-sm-6" style="margin-top: 20px; float: left; padding-left: 0">
<label for="reg_input">Açıklama</label>
<textarea name="MasrafAciklama" class="form-control" style="resize: none;"> </textarea>
</div>
</div>
我该如何追加
@Html.Action("_MasrafTurleriniGetir", "Ortak", new { ID = 0 })
使用javascript进入div吗?
我试过了
$("#myDiv").append('<%=Html.Action("_MasrafTurleriniGetir", "Ortak", new { ID = 0 })');
但它不起作用。
您显然正在使用Razor视图引擎,因此应该可以使用
$("#myDiv").append('@Html.Action("_MasrafTurleriniGetir", "Ortak", new { ID = 0 })');
还要确保javascript是cshtml
文件的一部分,而不是外部JavaScript文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.