Very new to MVC development, and for our project, we're communicating RESTfully with a SQL database. In my case, I have two Controllers, DrugEntriesListController and DrugEntryController. The former is derived from Controller and controls a web page view, while the latter is derived from ApiController and handles RESTful HTTP POST/GET with our database through a repository class (tutorial I followed is this one).
In my web page, you can upload a file (using this tutorial), which routes to the DrugEntriesListController via the built-in Request class that tracks uploaded files. From there, I can send said files to be parsed, etc. However, my issue is this: in order to RESTfully upload the parsed data to the DB, I need to go through DrugEntryController, since it is an ApiController and has the HTTP POST/GET calls. Problem is, I have no idea how to access it without instantiating a new one from either the view Controller or other files.
Perhaps I'm misunderstanding (very likely), but the ApiController is interacted with via the DrugEntriesList view Index.cshtml, here's my current code:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="body">
<ul id="drug_entries"></ul>
</div>
@section scripts{
<script type="text/javascript">
$(function ()
{
$.getJSON('/api/DrugEntry', function (drugEntriesJsonPayload)
{
$(drugEntriesJsonPayload).each(function (i, item)
{
$('#drug_entries').append('<li>' > + item.NDC + '</li>');
});
});
});
</script>
}
Upload a new .CSV file for the Drug Database:
@using (Html.BeginForm ("",
"DrugEntriesList",
FormMethod.Post,
new {enctype="multipart/form-data"}))
{
<input type="file" name="newCSV" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />
}
Since I've got a wall of obfuscated gibberish, the tl;dr is that I need to get information received in a Controller into an already existing ApiController.