Solved

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

Posted on 2011-09-20
5
3,325 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 250 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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