开发者

how to assign the button id dynamically in MVC Action

开发者 https://www.devze.com 2022-12-26 08:13 出处:网络
i declare the button 开发者_开发百科in .aspx its id is btn1 My prob is ,i need to assign the class name of the button and value of the button in action side(i.e in controller)Use the ViewData diction

i declare the button 开发者_开发百科in .aspx its id is btn1

My prob is ,i need to assign the class name of the button and value of the button in action side(i.e in controller)


Use the ViewData dictionary.

public ActionResult Show()
{
    ViewData["ButtonClassName"] = "my-class-name";
    ViewData["ButtonId"] = "my-id";
    View();
}

And in the view:

<%= Html.SubmitButton("name", "text", new { @class = ViewData["ButtonClassName"], id = ViewData["ButtonId"] }) %>
0

精彩评论

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