Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
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…

631 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