Well i have a complex form view model like this :
public class TransactionFormViewModel
{
public Session SessionRecord { get; private set; }
public IEnumerable<Resource> ResourcePerSessionRecord { get; private set; }
public Person PersonRecord { get; private set; }
public decimal SubTotal { get; private set; }
public TransactionFormViewModel(Person patient, Session session, IEnumerable<Resource> resourcePerSession)
{
this.PersonRecord = person;
this.SessionRecord = session;
this.ResourcePerSession = resourcePerSession
this.SubTotal = CalculateSubTotal();
}
private decimal CalculateSubTotal()
{
return ResourcePerSession.Sum(x => x.Cost);
}
}
This is my Model, which i use in the view, which (view) looks like this:
<A table that shows Person data></table>
<A table that shows a review of the Session> </table>
<!-- the submit button i need to complete the transaction -->
<% using (Html.BeginForm("PayNow", "Session"))
{ %>
<div id="trans-ses-footer">
<%:Html.HiddenFor(x => x.SessionRecord.SessionID) %>
<%:Html.HiddenFor(x => x.SessionRecord.PersonID) %>
<%:Html.HiddenFor(x => x.SubTotal) %>
<input type="submit" value="Pay" />
</div>
<% } %>
</div>
The controller looks like this: [HttpPost] public ActionResult PayNow() { //the transaction model Transaction transaction = new Transaction();
transaction.SessionID = int.Parse(Request.Form["SessionRecord.SessionID"]);
transaction.PersonID = int.Parse(Request.Form["SessionRecord.PersonID"]);
transaction.TotalCost = decimal.Parse(Request.Form["SubTotal"]);
transaction.Paid = true;
_sessionRepository.SaveTransaction(transaction);
TempData["TransactionMessage"] = "The transaction was saved successfully.";
return View();
}
I'm using Request.Form in order to get the values i need for the transaction. If i want to do it like this :
Public ActionResult(Transaction transaction)
{
if(ModelState.IsValid)
_transactionRepository.SaveTransaction(transaction)
etc...
}
i need to create a custom model bidder i guess. Is it worth the trouble? Will i gain anything in performance or in any other aspect? Or do you know any other method that i can do this kind of thing? I dont know how to express it correctly this scenario, so i couldn't find anything relevant... Thank you in advance.