Answer the question
In order to leave comments, you need to log in
How to get one of the passed parameters?
Using ActionLink I pass several parameters:
@Html.ActionLink("Вход", "Dialog", null,
new
{
@class = "openDialog",
data_dialog_id = "entry",
data_dialog_title = "Вход",
data_dialog_width = "auto",
data_dialog_height = "auto"
})
Answer the question
In order to leave comments, you need to log in
Good afternoon!
Perhaps the question is still relevant, so I will answer.
To pass a parameter to an action method, you need the action method itself to accept the parameter (as chydaya correctly pointed out ):
public ActionResult Dialog(string dataDialogId)
{
//...
return View();
}
routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
@Html.ActionLink("Вход", "Dialog", null,
new
{
@class = "openDialog",
data_dialog_id = "entry",
data_dialog_title = "Вход",
data_dialog_width = "auto",
data_dialog_height = "auto"
})
Html.ActionLink(article.Title,
"Item", // <-- ActionMethod
"Login", // <-- имя контроллера
new { id = article.ArticleID }, // <-- Передаваемые параметры.
null // <-- htmlArguments, эта коллекция служит для назначения параметров элементу html, который будет сгенерирован.
)
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/d={data_dialog_id}a={data_dialog_title}",
defaults: new { controller = "Home", action = "Index", data_dialog_id = UrlParameter.Optional, data_dialog_title = UrlParameter.Optional }
);
First, no parameters in your code are passed anywhere except to the link attributes.
Secondly, if you need one parameter, then pass one parameter
@Html.ActionLink("Вход", "Dialog", new { data_dialog_id = "entry" },
new
{
@class = "openDialog",
data_dialog_id = "entry",
data_dialog_title = "Вход",
data_dialog_width = "auto",
data_dialog_height = "auto"
})
public ActionResult Index(string data_dialog_id){
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question