What is the best way to keep "references" between entities in CRUD operations through Action calls?
Let's say, I need to create a new product for the current client. How should I "transfer" the PK of my current client into the form of the new product in a different view.
At the Moment I'm using the Session
container to store the PK of the client when the page is visited, but this way might be hard to maintain after several Actions.
Any idea about this? Does ASP.NET MVC provide anything for this kind of tracking?
Code sample:
For example to set a key when clicking somewhere in the gridview:
<script type="text/javascript">
function OnFocusedCampaignRowChanged(s, e) {
debugger;
var tmp = s.GetRowValues(s.GetFocusedRowIndex(), "CampaignPK", SelectCampaignCallback);
}
function SelectCampaignCallback(values) {
debugger;
$.ajax({
type: 'GET',
url: '/Session/SetSessionKey',
data: { key: "campaignPK", value: values[0] },
sucess: function (response) {
//alert("OK!");
//alert(values[0]);
},
error: function (xhr) {
//alert("ERROR:xhr");
alert('ERROR::SetSessionKey!' + xhr.responseText);
}
});
}
</script>
And then in my views I check things like this:
@if ((Session["ProductList"] as List<BaseProductViewModel>) != null)
{
@Html.Partial("ProductListPartial", (List<BaseProductViewModel>)Session["ProductList"]);
}
else
{
@Html.Partial("EditableListPartialView");
}
Or:
settings.CallbackRouteValues = new
{
Controller = "CheckMonitor",
Action = "ClientSelected",
brandPK = Session["clientPK"]
};