asp.net-mvc


overload ActionResult


this is my action "Index"
when i first go to page i dont have the "pageParent"
so i dont get the page.
just if i enter to it like this "http://localhost:50918/Page?pageParent=1" it's enter.
how to make "http://localhost:50918/Page" to work?
public ActionResult Index(int pageParent)
{
var id = pageParent;
var pages = (from p in db.pages
where p.pageParent == id
select p);
PageParentModel model = new PageParentModel();
model.page = pages;
model.pageParent = id;
return View(model);
}
Modify your Action like this
public ActionResult Index(int? pageParent) {
// this way your pageParent parameter is marked to be nullable
// dont forget to check for the null value in code
}
You can set a default value for use too in the case that the parameter isn't supplied in the querystring - e.g.:
public ActionResult Index([DefaultValue(1)] int pageParent) {
}

Related Links

Can C# decision get better in my View
RedirectToAction redirecting to wrong place
Persistence-Ignorant ASP.NET Identity: Login system does not function but no errors
How can I use an #HtmlHelper inside a custom #HtmlHelper?
ModelState.IsValid - but not on the bound model
ASP.NET MVC Upload file
Bootstrap 3 long modal open fix postion
Sitefinity 9.2 MVC 5 Feather and Ninject - Error loading module, another module with the same name has already been loaded
HTML Changes Not Being Shown in Build for Visual Studio 2017
Replace string in Razor View
MVC5 : Retrieving newly created record and repopulating the partial view with newly created record
MVC give error Assembly are not loaded
identify which button is being clicked in mvc 5
Whitelisted azure outbound ip addresses not connecting to smtp server
Asp.net MVC Token Based Autnetication and Authorization
Asp.Net MVC Helper: create a global helper for loading view with or without layout

Categories

HOME
dynamic-programming
ffmpeg
unit-testing
vr
passwords
antlr4
wikipedia-api
regression
pie-chart
zebble
bluej
cobol
google-weather-api
command-line-interface
scrollbar
nanotime
aar
embed
helpers
countdown
teamcity-9.0
dotnetbar
ssms-2014
symbolic-math
shape
precision
dsl
yii1.x
scalability
iar
nest-thermostat
blockui
querydsl
api-doc
perl-module
solid-principles
caldroid
ipod-touch
eve
polymer-cli
easy-digital-downloads
xargs
rtems
ms-jet-ace
g-wan
easyhook
jvm-arguments
gpt
mysql-error-1050
turbo-c
gwt-material-design
bootstrap-slider
proc
ubuntu-15.04
qlpreviewcontroller
vb6-migration
bash-completion
google-api-ruby-client
jni4net
clientid
document-ready
materialdrawer
ospf
ironmq
python-2.3
core-data-migration
hypervisor
cocoon-gem
kindlegen
xsb
telescope
keypad
boost-coroutine
window-server
sbrk
srp
lightstreamer
data-dictionary
couchrest
micro-orm
asp.net-authentication
speaker
jmdns
timestamp-with-timezone
rgba
time-limiting
expression-encoder-sdk
mkreversegeocoder
codi
spquery
high-traffic
cassandra-0.7
arraycopy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App