سؤال

يعمل

<a href="@Url.Action("edit", "markets", new { id = 1 })" 
            data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a>

لا يعمل - لماذا؟

@Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"})

يبدو أنه لا يمكنك تمرير شيء مثل data-iCon = "Gear" إلى htmlattributes؟

اقتراحات؟

هل كانت مفيدة؟

المحلول

المشكلة هي أن خاصية كائنك المجهول data-icon له اسم غير صالح. C# لا يمكن أن يكون للخصائص شرطات في أسمائها. هناك طريقتان يمكنك الالتفاف على ذلك:

استخدم السطح السطحي بدلاً من DASH (ستقوم MVC تلقائيًا باستبدال السطح السفلي باندفاع في HTML المنبعث):

@Html.ActionLink("Edit", "edit", "markets",
      new { id = 1 },
      new {@class="ui-btn-right", data_icon="gear"})

استخدم الحمل الزائد الذي يأخذ في القاموس:

@Html.ActionLink("Edit", "edit", "markets",
      new { id = 1 },
      new Dictionary<string, object> { { "class", "ui-btn-right" }, { "data-icon", "gear" } });

نصائح أخرى

استبدال الواصلة المطلوبة مع السطح السفلي. سيتم تقديمه تلقائيًا كوصلة:

@Html.ActionLink("Edit", "edit", "markets",
    new { id = 1 },
    new {@class="ui-btn-right", data_icon="gear"})

يصبح:

<form action="markets/Edit/1" class="ui-btn-right" data-icon="gear" .../>
@Html.ActionLink("display name", "action", "Contorller"
    new { id = 1 },Html Attribute=new {Attribute1="value"})
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top