如何使用javascript附加Html.Action进行查看

时间:2014-03-03 08:35:59

标签: javascript asp.net asp.net-mvc

我正在尝试通过单击“添加新按钮”添加新行。行包含在

下面
<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 })');

但它不起作用。

1 个答案:

答案 0 :(得分:2)

您显然正在使用Razor视图引擎,因此这应该可以正常工作

$("#myDiv").append('@Html.Action("_MasrafTurleriniGetir", "Ortak", new { ID = 0 })');

还要确保javascript是cshtml文件的一部分,而不是外部JavaScript文件。

相关问题