0

I have a 2 samlple model like this (I have enterd intered the fields whicj I want only )

[Table("TripAllocation", Schema = "dbo")]
public class TripAllocation
{
    public int TripAllocationId { get; set; }
    public ICollection<Requisition> Requisitions { get; set; }

}


[Table("Requisition", Schema = "dbo")]
public class Requisition
{
    [Key]
    public int RequisitionId { get; set; }

    public int? TripAllocationId { get; set; }
    public TripAllocation TripAllocation { get; set; }

}

So Now I want to select values to TripAllocationId in the Requisition table through TripAllocation table. I dant want to do it by creating driodownlist in the requisition view.

I want to do it from TripAllocation table and add list of the Requisitions for a TripAllocationId..

So how can I do this by Using MVC with handling Controller and the View.

(When I creating a Trip, List of Requistion should be applied to one AllocationTripId)

tereško
  • 58,060
  • 25
  • 98
  • 150
Anuradha
  • 1
  • 2

2 Answers2

0

I don't know if I fully understand your question, but it sounds like you want your view to display a list of requisitions searching by a TripAllocationId?

First, an assumption of mine based on your code sample, is that you're using LINQ-to-SQL which I haven't used for quite some time so forgive me if my code sample isn't 100% complete. But basically, you just need to use the DataContext to eager load the Requisitions on a TripAllocation. Your controller method would look something like this:

public ActionResult Requisitions(string id)
{
    TripAllocation allocation;
    List<Requisition> requisitions;

    using (var context = new MyDataContext)
    {
        allocation = context.TripAllocations.SingleOrDefault(c => c.TripAllocationId == id);
        requisitions = allocation.Requisitions.ToList();
    }

    return View(requisitions);
}

If I've understood your question correctly, you'll pass your controller method a TripAllocationId and it will use LINQ-to-SQL to navigate the object graph and return to the view a List<Requisition>.

sellmeadog
  • 7,437
  • 1
  • 31
  • 45
  • This is basically what i want. When I creating TripAllocation by Trip Allocation. I want to add some list of requisition for one raw of TripAllocation. (But I can Do simply when im creating a Rquisition, i can add a TripAllocation for one instant of Requisition by creating a dropdownlist in the requistion creation view. but its not the thisng i want. I want to do opposite of this) – Anuradha Aug 08 '12 at 03:17
0

This is basically what i want. When I creating TripAllocation by Trip Allocation. I want to add some list of requisition for one raw of TripAllocation. (But I can Do simply when im creating a Rquisition, i can add a TripAllocation for one instant of Requisition by creating a dropdownlist in the requistion creation view. but its not the thisng i want. I want to do opposite of this)

Anuradha
  • 1
  • 2