razor mvc trying to use button click to invoke server method

somewhere? Seen this asked many times, but solutions do not work..

the button definition above is standard. But, the question being asked here is how to invoke any method, anywhere when a click happens?? I can use the tag for a link; i would like to use a button.
The answer will be Whatever is needed to make: A button such that when the button is clicked, some method on one of the controllers can be invoked?

razor MVC web page. Add a button and it invokes a method, possibly passing data? so something in C# code in the controller.

UPDATE: question too confused, vague, not clear enough.

put this into the details.cshtml page. button click now calls method 'test' in controller 'Index'. web page crashes saying no, there aint no Actionresult and no View controller found for test, looked in /Index/test (and ~10 other file locations)

this could be useful, but the goal is to call some method that could do some c# code, modify webpage contents then return and continue where it was

what happens now, that shouldnt, is the button click pulls a new web page. what should happen is the button click method is called, its an empty "return", and the page simply continues where it was.

Added a view for test. now? blank page


There are several samples on how this would work and you really should provide more detail in what you have tried. But besides those tips, I would strongly recommend thinking in plain html and not in WebForms terms, like Button_Clicks.

When you think in html, you can submit - or 'post' - a form. Exactly as you have already discovered, one form can post to one action. But there is nothing stopping you for creating several forms on your page.

This is definitely not the most eloquent solution, but it is exactly what you are asking for and it will work:

<!-- button1 -->
@Html.BeginForm("Action1", "ControllerName", new { ... parameters ... }) {
<button type="submit">Button1</button>

<!-- button2 -->
@Html.BeginForm("Action2", "ControllerName", new { ... parameters ... }) {
<button type="submit">Button2</button>

Repeat it at will and you can have the greatest button galore you can imagine. Look into Html.AjaxForm instead of Html.BeginForm if you want to create an AJAX call, rather than a form post.

Category:javascript Time:2018-12-11 Views:2

Related post

  • Get dorodown list selected value which is filled in javascript on button click event on server side 2010-04-06

    I am using ASP.Net 3.5. I have fiiled dropdown list in javascript using ajax service but unable to get its selected value in button click event on server side. --------------Solutions------------- Is it an asp.net server control or a select list gene

  • jquery submit form not calling button click event at server side 2011-03-15

    i am using asp.net and following code to submit form on enter key press it is working but only refreshing same page and not calling button click event in server side code and without saving data it is comming back to same form, even without the jquer

  • Android softkeyboard invoke using button click 2011-04-01

    May I know is it possible to invoke android softkeyboard or Softkeyboard sample provided in the Androidsdk sample by button click? As of now I could invoke the softkeyboard only on edit view control's focus. As per the below suggestion I did the foll

  • How do I enter the text in the specific textbox using button click 2011-12-03

    I am working on a WinForms application. There are four text boxes and one button in my form. I am using textBox1.SelectedText += "any string" on a button click so it writes to the first TextBox. If I add textBox1.SelectedText += "any string." then it

  • use button click event to load usercontrol 2012-04-18

    Now I am trying to use a button on the parent page to a usercontrol. There is a checkboxlist on the usercontrol, and its datasource is read from database the checkboxlist didn't load correctly. it is like: OnlineRenewa_draft1.tbl_LanguageChoices Onli

  • Help using button click to display gallery view 2011-03-31

    I'm trying to make a simple app that has a main screen with buttons. Clicking on a button will view a new screen with a gallery. Every time I click the button it FC and I can't figure out what I'm doing wrong. Activity1.java Button next = (Button) fi

  • Close Safari popover using button click within popover 2012-04-26

    I am working on a Safari extension which displays a popover on clicking the toolbar button. I have added 2 buttons in the popover cancel and save. I want to dismiss the popover on clicking the buttons. How can I do this? I tried using self.close() bu

  • How to use button.click in gridview row bound event 2011-11-07

    Gridview has auto-generated column.I wanted to select the perticular row,so added one button in gridview.In rowbound event,i want like if(btnshow.click){//color code for that row}.Does it right way.Button is not visible in this event(when I am making

  • Moving previous image in ScrollView using button click 2011-12-22

    When I press previous button it does not take any effect. Next Button is working properly but previous button do not show previous image. I am using scroll view to load images: - (IBAction)next{ int arraycount = [appDelegate.articles count]; for (int

  • asp.net mvc getting id of button clicked 2010-05-29

    <div id="4591" > <input type="text" id="Title1" name="Title1" value="a" /> <input type="submit" name="button" value="Save" /> </div> <div id="4592" > <input type="text" id="Title2" name="Title2" value="a" /> <in

  • How To highlight imageview using button click event in android 2011-03-04

    I m new to android Development i have to place 3 button on screen and below that 3 image will be place below that..when i click on any button ,particular image should be highlight. can anyone tell me how to start..i only want suggestion from where to

  • Using button click to open helpProvider c# 2011-07-21

    Just a quick question but is it possible to open a helpProvider? All I want is open a CHM help file when I click a button in addition to the F1 key? If it’s not possibly anyone know of a work around? Thanks Peter --------------Solutions-------------

  • how to do sorting in repeater control using button click? 2012-03-09

    I have a repeater control in which i am showing values from database and i need to do sorting using a link button Here is my code <div class="demo"> <ul id="sortable1" class="connectedSortable" style="border-style: groove; border-width: inhe

  • redirect to different pages on selected radio button using button click 2014-01-09

    The following image is a pop up that details risk warnings and then asks users to choose one of the two radio buttons. When 'I agree'(Submit) button is clicked, it should redirect to different pages based on which radio button is selected. The submit

  • asp.net mvc trying to use session but controllercontext is null 2010-03-10

    i am trying to store an object in session.. in one controller, i create the object and put it in session. MyObject _o = new MyObject(); Session["MyObject"] = _o; MyObject _oo = (MyObject)Session["MyObject"]; // added for testing purposes, is not null

  • ASP.NET MVC tries to use ControllerFactory to load resources? 2010-11-01

    I've created a controller factory to be able to use Unity to resolve controller dependencies. I get the following error: The IControllerFactory 'My.Name.Space.MyControllerFactory' did not return a controller for the name 'favicon.ico'. Why does it tr

  • DSN tests ok, but login failure trying to use the DSN to SQL Server 2005 2009-08-30

    I'm writing a small ASP.NET application in a hosted environment (meaning I don't own the server). Using the hosting provider's webtools, I created a DSN that specifies the Driver, the Server, the UID, the PWD, and the Database. When I test the connec

  • RESTful modeling of button presses that invoke server side actions to a resource 2010-01-13

    I'm embarking on a new web app we want do do it RESTfully. Now it is time to begin designing the interactions, and something sorta basic about REST has me stumped. I am trying to figure out the best way to mediate the impedance mismatch between REST

  • how to access Custom EventArgs class in Button click event? 2011-03-23

    As a follow up to: access values within custom eventargs class How do I access public variables within custom Eventargs class, using button click or any other method? Example Custom Event Args class: public class TraderEventArgs: EventArgs { private

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 1.093 (s). 13 q(s)