Tengo condición if y deseo desactivar o habilitar mi botón actionLink.MVC3 Cómo deshabilitar/habilitar ActionLink
¿Cómo lo haría?
@Html.ActionLink("Delete", "Delete", new { id = @Model.Id})
Gracias,
Tengo condición if y deseo desactivar o habilitar mi botón actionLink.MVC3 Cómo deshabilitar/habilitar ActionLink
¿Cómo lo haría?
@Html.ActionLink("Delete", "Delete", new { id = @Model.Id})
Gracias,
Si conoce en el lado del servidor que el enlace no está disponible, entonces simplemente hacer que un mensaje de que la acción no está disponible:
@if(condition)
{
@Html.ActionLink("Delete", "Delete", new { id = @Model.Id})
}
else
{
<text>Action is not available</text>
}
De lo contrario sólo se puede desactivar un enlace con
para que funcione entre navegadores: Should the HTML Anchor Tag Honor the Disabled Attribute?
Para desactivar una "una" etiqueta que puede hacer:
@Html.ActionLink("Delete", "Delete", new { id = @Model.Id}, new { onclick = "javascript:return false;" })
O puede usar jQuery:
@Html.ActionLink("Delete", "Delete", new { id = @Model.Id}, new { class = "linkdisabled" })
CSS:
.linkdisabled{
cursor:text;
}
JQuery:
$function(){
$(".linkdisabled").click(function(){
return false;
}
}
Tal vez usted puede crear su propia interfaz de usuario de tipo MvcHtmlString
public static MvcHtmlString MyActionLink(this HtmlHelper helper, bool isClickable, string altText, RouteValueDictionary routeValues, object htmlAttributes = null)
{
// some logic with isClickale parameter here
if(isClickable == false)
{}
return new MvcHtmlString(helper.ToHtmlString());
}
y utilizarlo en su Ver
@Html.MyActionLink(// some parameters here)
Pero nunca lo he probado. Intente encontrar algo sobre MvcHtmlString en Google.
Hola, buena solución ... pero ¿hay alguna manera de hacer que el texto no se pueda hacer clic? Ahora aparece como un enlace pero no va a ninguna parte. Entonces, ¿hay alguna manera de cambiar su apariencia? Gracias – Scorpion
Puede agregar un atributo de estilo o usar una clase css para hacer eso: –
¡Gracias! Buena solución! –