Solved

How do I call a function (Razor) from a button click event.

Posted on 2011-09-20
5
3,255 Views
Last Modified: 2012-05-12
I have an InvoiceEdit.cshtml page. i have written a @function {public List<int> AddInvoiceFeeItem (List<int> feeList) { } in InvoiceEdit.cshtml. I can call the function inline in the page ( @AddInvoiceFeeItem(); ) and it works just fine.

How do i call this same function from a user initiated event like a button.click or link click ?
0
Comment
Question by:Courts-Tech
  • 3
  • 2
5 Comments
 

Author Comment

by:Courts-Tech
Comment Utility
I am fairly new to MVC, Razor.
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
Comment Utility
Well MVC is all about actions, so you simply create a link to the controller/action and expose the functionality through an action.

@Html.ActionLink(@Person.Name, "EditPerson", new { id = @Person.Id }
0
 

Author Comment

by:Courts-Tech
Comment Utility
I'm still not clear on this.  My @function, named AddInvoiceFee, (residing inside the .cshtml file) returns a List<int> and it accepts a List<int> as a parameter.  I am not sure how the ActionLink can call the AddInvoiceFee function (that is not part of a controller/action) and further more, how does it retrieve the return value of the function.

Like I said on my first comment, I'm fairly new to MVC and Razor.
0
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 250 total points
Comment Utility
Sorry. Chaotic at the moment. So, .net code is server side. It is not included in the final html.do a "view source" on the page and you will see. So you'd want to use javascript on the client side or expose that.net functionality via a new action.
0
 

Author Closing Comment

by:Courts-Tech
Comment Utility
I apologize for the late response... had to set aside the project I was working on.  The solution did not really addressed my question in a way that I could understand.  I did mention that I am new to MVC/Razor and I was looking for more of a code example as an answer.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now