I want that controller will accept /Details/1 and /User/xxx but not /User/
and i try it like below=>
public ActionResult Details( Nullable<int> id, Nullable<string> name)
{
if (((id ?? 0) == 0) && name == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Instructor instructor = db.Instructors.Where(x => x.InstructorId == id || x.faculty_name.Equals(name)).SingleOrDefault();
if (instructor == null)
{
return HttpNotFound();
}
ViewBag.faculty_active = MyCustomFunctions.UserActivity();
return View(instructor);
}
i want that(mansion above) user can pass /Details/1 or /Details/xxx but not /Details/ thats why i add condition check=>
if (((id ?? 0) == 0) && name == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
but i wants to run the code the compiler gives me error something like=>
i was thinking that was perfect but i dont know why a have done wrong = i tried=>
public ActionResult Details( int? id, string? name)
{
}
that was also gives me the same error.i searched about this problem and i found=> ASP.NET MVC Overriding Index action with optional parameter
i am not understanding anything . thats why i reposed this kind of problems. this will be great full if anybody can help me?
stringis already nullable. But you cannot have 2 nullable values as parameters and use routes (you will only be able to generate/Details?name=xxx- if you were to use/Details/xxxboth parameters will benulland your code will always returnBadRequest)string) and then check if it can be parsed toint