So I got this webproject i'm working on, and in 4/5 views Im using
@Html.ActionLink("Back to List", "Index", new { id=Model.ClientID})
All of the views return me to my list exept my "Create New View" This will also be the only view not to load, giving me the exeption of "System.NullReferenceException"
I'm confused on why this is the only view that won't let me pass a clientID to it ( since i need not only it but also the CountyID to create a new County, And more so telling me that it is null.
If i remove the line of code above my code runs fine ( exept adding my 2 ID fields into the create view obviously ) wich made me think it may be my controller.
Here is my action from givin controller for create
// GET: /County/Create
public ActionResult Create()
{
return View();
}
for comparison here is an edit action in the same controller
public ActionResult Edit(int id = 0)
{
dbCounty countys = db.Countys.Find(id);
if (countys == null)
{
return HttpNotFound();
}
return View(countys);
}
I've also tryed adding this code to the create new actionlink wich is when i get this error
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.
What am i doing wrong here ....
My project is build on a hierachy model, One Client Many Countys ( if you need more code let me know )
thanks in advance.
Tip:
there must be a reason ( my assumption ) why when removing this line of code it works ( so it must be this line of code ?? ) - must be a different way of passing it ( clientID does have a value of 1 )
@Html.ActionLink("Back to List", "Index", new { id=Model.ClientID})
Edit Index Controller needed :
public ActionResult Index([Bind(Prefix="id")] int CID=0)
{
var clnt = db.Clients.Find(CID);
if (clnt != null)
{
return View(clnt);
}
return HttpNotFound();
}
EDIT: new create action from Countys Controller
public ActionResult Create(int id=0)
{
dbCounty countys = db.Countys.Find(id);
if (countys == null)
{
return HttpNotFound();
}
return View(countys);
}
i have also tryed running
public ActionResult Create(int id=0)
{
dbClient Client = db.Clients.Find(id);
if (Client == null)
{
return HttpNotFound();
}
return View(Client);
}
( since i am passing a clientID - the way the models are built it should add a county id while creating this new row in the database with the clientID(passedVariable)