14 EKİM 2008, Salı
HTML.ActionLink metodu
Hadi bir sınıf var diyelim
public class ItemController:Controller
{
public ActionResult Login(int id)
{
return View("Hi", id);
}
}
ItemController
bulunduğu Madde klasörde bulunan bir sayfa üzerinde,, Login
yöntemi için bir bağlantı oluşturmak istiyorum. Ve parametreleri geçiyorum ne yapmalıyım? kullanmalıyım yani
Özellikle, bu yöntem yerine arıyorum
Html.ActionLink(article.Title,
new { controller = "Articles", action = "Details",
id = article.ArticleID })
bu son ASP.NET MVC yaşamında da emekli olmuştur.
CEVAP
14 EKİM 2008, Salı
İstediğin şey sanırım bu
ASP.NET MVC1
Html.ActionLink(article.Title,
"Login", // <-- Controller Name.
"Item", // <-- ActionMethod
new { id = article.ArticleID }, // <-- Route arguments.
null // <-- htmlArguments .. which are none. You need this value
// otherwise you call the WRONG method ...
// (refer to comments, below).
)
Bu aşağıdaki yöntemi ActionLink imza: kullanır
public static string ActionLink(this HtmlHelper htmlHelper,
string linkText,
string controllerName,
string actionName,
object values,
object htmlAttributes)
ASP.NET MVC2
iki argüman etrafında yer değiştirdi
Html.ActionLink(article.Title,
"Item", // <-- ActionMethod
"Login", // <-- Controller Name.
new { id = article.ArticleID }, // <-- Route arguments.
null // <-- htmlArguments .. which are none. You need this value
// otherwise you call the WRONG method ...
// (refer to comments, below).
)
Bu aşağıdaki yöntemi ActionLink imza: kullanır
public static string ActionLink(this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
object values,
object htmlAttributes)
ASP.NET MVC3
bağımsız MVC2, ıd değerini ancak artık gerekli olduğu gibi, aynı sırayla
Html.ActionLink(article.Title,
"Item", // <-- ActionMethod
"Login", // <-- Controller Name.
new { article.ArticleID }, // <-- Route arguments.
null // <-- htmlArguments .. which are none. You need this value
// otherwise you call the WRONG method ...
// (refer to comments, below).
)
Bu sabit kodlama bağlantıya herhangi bir yönlendirme mantığı engeller.
<a href="/Item/Login/5">Title</a>
Bu aşağıdaki html çıktısını varsayarak verecektir:
article.Title = "Title"
article.ArticleID = 5
- yine de aşağıdaki yol tanımlamıştır
. .
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
Bunu Paylaş:
ASP.NET mvc Html çapa etiketinin de da...
HTML.Vs Url ActionLink.ASP.NET Jilet e...
Html.Bir düğme olarak ActionLink veya ...
Html.Dinamik olamaz ActionLink gönderi...
Html Kullanarak.ActionLink farklı dene...