I am building a MVC4 project with razor engine, although I don’t know if that has relevance to my problem.
I have a VendorBillController with a Submit(String poId) ActionResult.
My link looks like this:
example.com/VendorBill/Submit?poId=790a2e76-5186-42c1-8087-c13b18d22023
However, when trying to go to this page, I get this error:
The view ‘722884’ or its master was not found or no view engine
supports the searched locations.
Why is it looking for the view 722884? Although I was pretty sure numbers, letters, and dashes were OK in html links, I tried html encoding the link as well but nothing changes.
if I put in
example.com/VendorBill/Submit?poId=asdf
It makes it to the function, but then fails because the poId is passed into new Guid() and asdf is not a guid.
Why does a guid in a URL fail? Is there a ‘normal’ work around for this, when a guid is the ID that needs to be passed?
edit:
Here is the code for my entire controller:
It doesn’t work with guid either, here is my entire controller, however I don’t think it’s even getting there so i’m not sure it’s the issue:
public class VendorBillsController : Controller
{
public ActionResult Submit(Guid poId)
{
var purchaseOrderId = new Models.Entities().TempLinks.AsQueryable().Single(x => x.Guid == poId).PurchaseOrderId;
return View(purchaseOrderId.ToString());
}
}
}
Does it work if you change the signature of
SubmittoSubmit(Guid poId)?There is no issue with using GUIDs natively in MVC it will convert them for you.
If the above doesn’t work, can you please include the code of the controller method so we can have a look at it?
Update: No, your problem is this:
return View(purchaseOrderId.ToString());If you pass a string into View, it assumes that what you’re passing is the name of the view (see this on MSDN), if you want your view model to be of type
stringthen you’re going to have to pass the view name in as the first parameter, then the master view name, then the string value (this overload). Much easier to declare an explicit view model which has a single propertyPurchaseOrderIdthen pass that in to the view method. The way theViewmethod overloads are setup you can use any view model type except string.You could just pass it in if it was a GUID, but you have to pass it in as a GUID, don’t call
ToString()