c#
Only assignment, call, increment, decrement, and new object expressions can be used as a statement in mvc
I'm trying to get the amount from one of my tables in DB by using inline if in my controller public ActionResult IfPaid(int id) { Ref_ViewModel = new View_model.View_Model(); Ref_ViewModel.GetAllCustomers(id).Any(p => p.Paid == false) ? RedirectToAction("Pay", "Account") : RedirectToAction("Download"); } I get this error in the last line Only assignment, call, increment, decrement, and new object expressions can be used as a statement How can we fix this?
You should add a return statement: public ActionResult IfPaid(int id) { Ref_ViewModel = new View_model.View_Model(); return Ref_ViewModel.GetAllCustomers(id).Any(p => p.Paid == false) ? RedirectToAction("Pay", "Account") : RedirectToAction("Download"); } As the error message says, the ternary operator on its own is not a statement. It can be part of another statement - e.g. return statement as above, or assignment statement int value = condition ? 0 : 42; Further reading: Statements (C# Programming Guide)
Related Links
C# Linq to SQL, find Min and Max dates in grouped rows
ObservableCollection<T>(List<T>)
Microsoft SQL lambda: Combining columns for searching
How to insert Value from textBox to dataGridView in c#
Confused on passing parameter to MVC Partial View?
Xamarin Forms - Preserve Basic Authentication after redirect?
Generic Expression.Call for aggregate functions
how to add color to sub item in listview? c#
C# + BLE: Heart Rate Monitor keeps disconnecting, code receives no values
How to properly implement JWT using client_id and client_secret to authenticate?
How do I make http request wait for 5 seconds before getting the response?
Invalid certificate received from server. Error code: 0xffffffff800b010a Mono
trying to create new player data from template
What are the ways a one-to-one relationship between a model List<> and a field in an ASP MVC view
Wrapping a Generic class inside a non Generic class C#
The name 'Item' does not exist in the current context out of forech [closed]