Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 11, 2012 03:42 PM by BrockAllen
Member
218 Points
152 Posts
Apr 11, 2012 02:56 PM|LINK
Hi
I hope this will be an easy one.
I have a view and the user submits some fields and then clicks save
I want to return the same view with an id parameter but so
Return View("ViewName/1")
with 1 being the parameter.
This gives me an error saying that the view ViewName/1.cshtml cant be found.
How do i pass the parameter?
Thanks in advance :)
260 Points
59 Posts
Apr 11, 2012 03:02 PM|LINK
You will need a nullable parameter in your controller:
public ActionResult Index(int? id) { // Your code here }
Apr 11, 2012 03:04 PM|LINK
Thanks for the reply
Sorry I dont understand how that relates to what i am asking
Thanks again
Contributor
3216 Points
710 Posts
Apr 11, 2012 03:10 PM|LINK
return View("ViewName", new { id = 1 });
Apr 11, 2012 03:17 PM|LINK
By adding in a nullable parameter, this will match your "Viewname/1" URL. In your Routes, you will probably have a default route of: {constructor}/{action}/{id}
Which will be used for this new method.
All-Star
27574 Points
4912 Posts
MVP
Apr 11, 2012 03:42 PM|LINK
Are you sure that you're not looking for a redirect?
return RedirectToAction("OtherAction", new{param=1});
ArchieEric
Member
218 Points
152 Posts
Easy One - Return View("ViewName/1")
Apr 11, 2012 02:56 PM|LINK
Hi
I hope this will be an easy one.
I have a view and the user submits some fields and then clicks save
I want to return the same view with an id parameter but so
Return View("ViewName/1")
with 1 being the parameter.
This gives me an error saying that the view ViewName/1.cshtml cant be found.
How do i pass the parameter?
Thanks in advance :)
Neil_Knight
Member
260 Points
59 Posts
Re: Easy One - Return View("ViewName/1")
Apr 11, 2012 03:02 PM|LINK
You will need a nullable parameter in your controller:
public ActionResult Index(int? id) { // Your code here }ArchieEric
Member
218 Points
152 Posts
Re: Easy One - Return View("ViewName/1")
Apr 11, 2012 03:04 PM|LINK
Hi
Thanks for the reply
Sorry I dont understand how that relates to what i am asking
Thanks again
JohnLocke
Contributor
3216 Points
710 Posts
Re: Easy One - Return View("ViewName/1")
Apr 11, 2012 03:10 PM|LINK
return View("ViewName", new { id = 1 });
Neil_Knight
Member
260 Points
59 Posts
Re: Easy One - Return View("ViewName/1")
Apr 11, 2012 03:17 PM|LINK
By adding in a nullable parameter, this will match your "Viewname/1" URL. In your Routes, you will probably have a default route of:
{constructor}/{action}/{id}
Which will be used for this new method.
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: Easy One - Return View("ViewName/1")
Apr 11, 2012 03:42 PM|LINK
Are you sure that you're not looking for a redirect?
return RedirectToAction("OtherAction", new{param=1});
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/