Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript将Html.Action附加到视图中_Javascript_Asp.net_Asp.net Mvc - Fatal编程技术网

如何使用javascript将Html.Action附加到视图中

如何使用javascript将Html.Action附加到视图中,javascript,asp.net,asp.net-mvc,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

我正试图通过单击添加新按钮添加新行。行包含以下内容

<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>
通过使用javascript进入div

我试过了

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

$(“#myDiv”).append(“您显然在使用Razor视图引擎,因此这应该可以工作

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

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

是的,它正在工作,但我在_MasrafTurleriGetir中使用了foreach循环,当我运行这个附加代码时,我得到了“unterminated string literal”错误,其中字符串来自_MasrafTurleriGetir。我添加了\和“unterminated string literal”问题解决了,谢谢。
$("#myDiv").append('@Html.Action("_MasrafTurleriniGetir", "Ortak", new { ID = 0 })');