Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-20
5
Medium Priority
?
3,714 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
ID: 36569327
I am fairly new to MVC, Razor.
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 36569722
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
ID: 36576143
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 500 total points
ID: 36580294
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
ID: 36927558
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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

926 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