JS函数无法从vbhtml获取值

时间:2018-09-20 02:01:48

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

我如何从html动作链接中获取值,我试图在js函数中设置该值,它是可行的,问题是js无法从html文件中获取值,而此forloop仅第一个会调用Javascript函数。

这是我的js函数

function selectTemplate(){

$('#choose').on('click', function () {

    var objTemplate = $(".styTemplate").val();
    $.post(strRoot + "/Home/Index/", { styTemplate: objTemplate });

});

};

这是我的vbhtml代码

            @For Each item In Model
                Dim currentItem = item

                '<!-- single-awesome-project start -->
                @<div Class="col-md-4 col-sm-4 col-xs-12 @Html.DisplayFor(Function(modelItem) currentItem.strTemplateType)">
                    <div Class="single-awesome-project">
                        <div Class="awesome-img">
                            <a href="#"><img src="@Url.Content("~/Content/TemplateCSS/img/portfolio/" & currentItem.strTemplateType & ".jpg")" alt="" /></a>
                            <div Class="add-actions text-center">
                                <div Class="project-dec">
                                    <a Class="venobox" data-gall="myGallery" href="@Url.Content("~/Content/TemplateCSS/img/portfolio/" & currentItem.strTemplateType & ".jpg")">
                                        <h4>@currentItem.strTemplateName</h4>
                                        <span> Web Development</span>
                                        @Html.ActionLink("Choose", "companyInfomation", "Home", New With {.id = "choose"}, New With {.styTemplate = currentItem.strTemplateName})

                                    </a>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                '<!-- single-awesome-project end -->

            Next

        </div>


        <script>

            selectTemplate();

        </script>

1 个答案:

答案 0 :(得分:1)

也许最好使用onclick属性?使用它代替Html.ActionLink:

<a href="@Url.Action("companyInfomation", "Home")" onclick="YourJSFunction(@currentItem.strTemplateName)">Choose</a>