TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tridip Bhattacharjee
NA
1.2k
78.1k
ASP.Net MVC:clicking on routelink url not passing all the da
Feb 5 2018 8:51 AM
i have creating url using routelink.
@Html.RouteLink(
"Edit"
,
"PageWithId"
,
new
{
controller =
"Customers"
,
action =
"Edit"
,
id = item.CustomerID,
page = ViewBag.CurrentPage
})
i am using this routing PageWithId with route link
routes.MapRoute(
name:
"PageWithId"
,
url:
"{controller}/{action}/{page}/{id}"
,
defaults:
new
{ controller =
"Customers"
, action =
"Edit"
, page = UrlParameter.Optional, id = UrlParameter.Optional }
);
i have 3 routing code. here is all
routes.MapRoute(
name:
"PageWithSort"
,
url:
"{controller}/{action}/{page}/{SortColumn}/{CurrentSort}"
,
defaults:
new
{ action =
"Index"
, page = UrlParameter.Optional, SortColumn = UrlParameter.Optional, CurrentSort = UrlParameter.Optional }
);
routes.MapRoute(
name:
"PageWithId"
,
url:
"{controller}/{action}/{page}/{id}"
,
defaults:
new
{ controller =
"Customers"
, action =
"Edit"
, page = UrlParameter.Optional, id = UrlParameter.Optional }
);
routes.MapRoute(
name:
"Default"
,
url:
"{controller}/{action}/{id}"
,
defaults:
new
{ controller =
"Home"
, action =
"Index"
, id = UrlParameter.Optional }
);
when i run my program the route link generate url like http://localhost:55831/Customers/Edit/1/ALFKI
when i click on the link the Edit action is getting called but customer id is getting null where as ALFKI is there in url as customer id.
here is my edit action details
public
ActionResult Edit(string id,
int
page)
{
if
(id == null)
{
return
new
HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Customer customer = db.Customers.Find(id);
if
(customer == null)
{
return
HttpNotFound();
}
ViewBag.CurrentPage = page;
return
View(customer);
}
please tell me why id is getting null when ALFKI as passing as customer id?
thanks
Reply
Answers (
1
)
Entity Framework 6: How to find the primary key?
How to stop playing videos in embed wmp player