Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

html - 调用MVC控制器和Action方法的HTML按钮(HTML button calling an MVC Controller and Action method)

I know this isn't right, but for the sake of illustration I'd like to do something like this:

(我知道这是不对的,但是为了说明起见,我想做这样的事情:)

<%= Html.Button("Action", "Controller") %>

My goal is to make an HTML button that will call my MVC controller's action method.

(我的目标是制作一个HTML按钮,该按钮将调用我的MVC控制器的action方法。)

  ask by Aaron Salazar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No need to use a form at all unless you want to post to the action.

(除非您要张贴到操作中,否则根本不需要使用表格。)

An input button (not submit) will do the trick.

(输入按钮(不提交)可以解决问题。)

  <input type="button"
         value="Go Somewhere Else"
         onclick="location.href='<%: Url.Action("Action", "Controller") %>'" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...