开发者

asp.net mvc and jquery trying to pass in list

开发者 https://www.devze.com 2022-12-09 23:10 出处:网络
i have a strongly typed asp.net-mvc view and the Model has a .Links property. Links is an array of link, which has a URL, a Description and an ID.

i have a strongly typed asp.net-mvc view and the Model has a .Links property.

Links is an array of link, which has a URL, a Description and an ID.

i have a bunch of links. Every links has a list of tags and those tags are layed out like this:

<a id="98" href="www.ibm.com>IBM</a><b class='dblclick'>Tags: Software</b>
<a id="99" href="www.microsoft.com>MIcrosoft</a><b clas开发者_开发百科s='dblclick'>Tags: Software</b>
<a id="100" href="www.apple.com>Apple</a><b class='dblclick'>Tags: Software, Fruit</b>

(www.ibm.com being the URL, IBM being the Description, and "98" being the ID)

i have the following jquery code:

<script type="text/javascript">
    $(document).ready(function() {

        $(".dblclick").editable('<%=Url.Action("UpdateSettings","Links", new { site = Model.Links[0].ID }) %>', {
            tooltip: "Doubleclick to edit...",
            event: "dblclick",
            style: 'display: inline; width:400px;'
        });

    });

the issue that i dont want to have: Model.Links[0].ID hard coded, i want to pass in the index into the method (98 in this case). Since every link has the "dblclick" class, how do i pass in the exact link or index into this array so i can stick in the ID field into this editable method?


You should get away with replacing:

Model.Links[0].ID  

With

$(this).prev("a").attr("id")

Although it would be better if you didn't have to traverse sideways as it is destined to cause problems. If you could put the ID on the "b" element, it would be as easy as

<a id="98" href="www.ibm.com>IBM</a><b class="dblclick" id="98">Tags: Software</b>

...

$(this).attr("id")

Also, you may need to think about those IDs as HTML id attributes aren't supposed to start with a number!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号