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

VS2015 Not able to edit cshtml files
An exception of type 'System.NullReferenceException' occurred in App_Web_jwfiir5n.dll but was not handled in user code
What should be written inside the connection string when migrating SQL db to Azure with VS2015?
Url delimiter with “-” MVC Routes
FoolProof MVC GreaterThan not working with time
Microsoft Word Online Edition in asp.net mvc web application
MVC Areas & Shared Layouts
automapper with pagedlist always return one page
Adding validation data attributes to custom input
Drop down toggle is not working in pagination
How can I destroy session in Asp.net MVC 5?
Include a sorted bundle to another bundle
ASP.NET MVC - The entity type IdentityRole is not part of the model for the current context
ASP.NET Bootstrap table padding between columns not working
MVC - ADFS Authentication - ADFS redirects to localhost
Error: “The resource cannot be found” when trying to pass in an empty object to View

Categories

HOME
lsf
performance-testing
dynamics-crm-365
direction
jsonschema
robot
logback
mocha
android-sms
delphi-xe7
c++14
regression
python-xarray
cobol
editor
nanotime
lighttpd
pyfftw
aar
libssh
afnetworking-2
media-source
game-maker-language
line-breaks
mouseevent
iteration
naturallyspeaking
parallax
dsl
esri
listbox
codewarrior
ocean
shinydashboard
dapper-fastcrud
vue-router
complex-networks
server-sent-events
ecmascript-4
signing
weebly
amazon-elasticsearch
dsx
hostname
angularjs-routing
appdynamics
uifont
name-mangling
vega-lite
mrtg
fido
jawr
assembly-references
waf
breach-attack
dr-memory
surroundscm
statistics-bootstrap
network-traffic
geneos
nuitka
intrinsics
flotr2
main-activity
pddl
cucumber-java
push-api
translate3d
size-t
diagonal
declaration
conditional-statements
kue
android-tablelayout
setattribute
slick2d
misra
mysql5
esx
liferay-hook
sqlhelper
iqueryable
cpp-netlib
controlsfx
nine-patch
hobbitmon
wmv
declspec
android-lru-cache
onejar
resolver
transport-stream
broadcom
python-dateutil
godaddy-api
hogan.js
pixelsense
locomotivejs
cakephp-2.1
libavg
tipsy
noindex
c++builder-xe2
sdl.net
mkreversegeocoder
ryz
ants

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