Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-20
5
Medium Priority
?
3,644 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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