httppostを呼び出すと、選択した値と、ドロップダウンリストの乱数のIDを取得する必要があります。ドロップダウンリストの数は、別のドロップダウンリストの選択された値に基づいて動的に作成されるため、ランダムです。 例:ドロップダウンリストの 1 bmwを選択します。次に3つのドロップダウンリストが作成されるので、ユーザーは各カーモデルにレート値を与えることができます。各ドロップダウンリストにはid =自動車のモデルがあり、選択できるオプションは1,2と3です。bmwの4つのモデルがあれば、オプションは1,2,3,4となります。 httppostを呼び出すと、どのようにしてコントローラがすべてのダイナミックに作成されたドロップダウンリストを実行し、値とIDをチェックするのですか?mvc3のドロップダウンリストから選択した値とIDを取得する方法は?
EDIT:私のindexビューの コントローラ:
public class BookingPensionController : Controller
{
private DbEntities db = new DbEntities();
EditBookingPensionViewModel objViewModel;
public ActionResult Index()
{
objViewModel = new EditBookingPensionViewModel
{
Booking = new Booking { BookingStartDate = DateTime.Today, BookingEndDate = DateTime.Today, DateOfBooking = DateTime.Now }
};
objViewModel.deliveryTypes = new List<string>();
int id = int.Parse(Session["id"].ToString());
SelectList list;
try
{
var deliverytypes = from d in db.DeliveryTypes
where d.Pension_ID == id
select d;
foreach (DeliveryType item in deliverytypes)
{
objViewModel.deliveryTypes.Add(item.Titel);
}
ViewData["DeliveryTypes"] = objViewModel.deliveryTypes;
objViewModel.customersToPension = new List<SelectListItem>();
objViewModel.customersToPension = GetCustomersToPension(id);
}
catch (Exception ex)
{
throw;
}
int PensionId = int.Parse(Session["id"].ToString());
objViewModel.CustomerValue = GetCustomersToPension(PensionId);
return View(objViewModel);
}
マイIndexビュー:
//Some more code...
//And then the table which gets populated with the random number of dropdownlists:
<table id="tblRooms" width="100%">
<tr>
</tr>
</table>
はViewModelには、次のようになります。
customerinfoと私partialviewは、次のようになります。
@model HundePensionBooking.Models.Customer
私はhttppostコール
<input type="submit" value="Create" />
を作るときに、私は私のデータベースまでのすべてのデータを取得する必要があります。それを行う方法についてのイムわからないが、私は
[HttpPost]
public ActionResult Create(EditBookingPensionViewModel model)
{
//SaveCustomer... From the CustomerInfo partialview
//SaveBooking...From Index view
//Save all the data from all the dropdownlists... from index view
}
投稿のFormCollectionには何がありますか? –
あなたが今作成したコードを投稿してください。問題がわかりやすくなります。 –
somコードを追加しました...もっと必要な場合はちょうど言う:) – Christian