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 MVC5: Extra segment in routing causes issue
Feb 9 2018 8:01 AM
to handle my routing issue i add extra segment in routing which not redirecting me to edit action.
see my routing which causing problem
routes.MapRoute
(
name:
"PageWithId"
,
url:
"Customers/Action/Edit/{page}/{id}"
,
defaults:
new
{ controller =
"Customers"
, action =
"Edit"
}
);
OR
routes.MapRoute
(
name:
"PageWithId"
,
url:
"Customers/Edit/Action/{page}/{id}"
,
defaults:
new
{ controller =
"Customers"
, action =
"Edit"
}
);
i test above 2 different set of routing for PageWithId but none work
see RouteLink code
@Html.RouteLink(
"Edit"
,
"PageWithId"
,
new
{
controller =
"Customers"
,
action =
"Edit"
,
id = item.CustomerID,
page = ViewBag.CurrentPage
})
my edit action code
public
ActionResult Edit(
int
page, string id)
{
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);
}
now tell why this url
http://localhost:2020/Customers/Action/Edit/1/AlFAKI
not redirecting me to edit action?
see my full routing code
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:
"Customers/Action/Edit/{page}/{id}"
,
defaults:
new
{ controller =
"Customers"
, action =
"Edit"
}
);
OR
routes.MapRoute
(
name:
"PageWithId"
,
url:
"Customers/Edit/Action/{page}/{id}"
,
defaults:
new
{ controller =
"Customers"
, action =
"Edit"
}
);
routes.MapRoute(
name:
"Default"
,
url:
"{controller}/{action}/{id}"
,
defaults:
new
{ controller =
"Home"
, action =
"Index"
, id = UrlParameter.Optional }
);
Reply
Answers (
2
)
Aspects Every ASP.Net Developers Must Know
cannot simplicity convert string to system.collection.generi