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]

Categories

HOME
postgresql
botframework
gsm
opc-ua
symfony-sonata
ebay
samsung-gear-s2
normals
openbsd
derby
swift3.1
android-actionbar
computation-theory
gomobile
minimagick
formulas
matlab-gui
android-xml
nsopenpanel
inspec
android-6.0-marshmallow
csproj
lines
language-detection
loopback
slim-lang
gstreamer-1.0
mybatis-generator
server-side-swift
google-cloud-powershell
collation
pexpect
xmldom
stanford-nlp-server
visio-2010
vertex
reloaddata
alarmmanager
easy-thumbnails
racket-student-languages
access-violation
patching
android-xmlpullparser
sbt-proguard
camellia
mod
sqlxml
hana-sql-script
methodology
dday
ewam
updating
exchange-server-2007
vanilla-forums
transparentproxy
minko
mri
sony-xperia
shunting-yard
javadb
formbuilder
system.net
xts
drawable
disabled-control
switchpreference
mvcgrid
rssi
pidgin
email-headers
db2-connect
nativequery
friendly-id
myrrix
wpa
backbone-views
symbian3
latex-suite
simplemembership
nx
cron4j
screensharing
linear-interpolation
certificate-revocation
beep
winrt-async
github-archive
datejs
conditional-operator
oaw
for-xml
code-golf
manuals
authkit
hotfix

Resources

Encrypt Message