0

Hi I'm working with MVC3 i want to insert the values displayed in front end into the table in backend.How can i achieve this?

Following is my view,

@model TravelReady_SupervisorInput.Models.TravelReadyModel
@{
   Layout = "~/Views/Shared/_Layout.cshtml";
}
<script language="javascript">
     $(document).ready(function () {
     $("#es").hide();
     $("#n").hide();
     $("#date").hide();
});    
</script>
<h2 class="filter">Associate Details</h2>
<fieldset class="fs">
@foreach (var item in Model.lstTravelReadyEntities)
{   
     <label class="Detail1"><b>Associate Id : </b>@item.Var_AssoId </label>
     <label class="Detail1"><b>Vertical :</b>@item.Var_Vertical</label>
     <label class="Detail1"><b>Visa ValidFrom :</b>@item.Dt_VisaValidFrom </label><br /><br />
     <label class="Detail2"><b>Associate Name :</b>@item.Var_AssociateName</label>
     <label class="Detail2"><b>Account Name :</b>@item.Var_AccountName</label>
     <label class="Detail2"><b>Visa ValidDate :</b>@item.Dt_VisaValidTill</label><br /><br />
     <label class="Detail3"><b>Grade HR :</b>@item.Var_Grade</label>
     <label class="Detail3"><b>Project Name :</b>@item.Var_Project_Desc</label><br />          
 }
<h2> Response Details</h2><br />
Supervisor Response :
<input type="radio" class="radi" name="radio" value="Yes" onclick="javascript:Getyfunc();">Yes
<input type="radio" name="radio" value="No" onclick="javascript:Getnfunc()">No
<div id="es">
<label style="padding-left:10px;">*Supervisor Inputs : 
    <select id="dropdown"  name="dropdown">
        <option value="0">Select</option>
        <option value="1">Available for Deployment/Release</option>
        <option value="2">Travel Planned</option>
        <option value="3">To Deploy For Same Account</option>
    </select>
</label>
<label>Comments If Any  
    <textarea name="comments" id="cmts"></textarea>
</label>
<br />
<br />
<label id="date">*Date of Travel  
    <input type="text" id="datepicker" onclick="$(this).datepicker().datepicker ('show')"/>
</label>
<br />
<br />
</div>
<div id="n">
<label style="padding-left:10px;">*Supervisor Inputs :
    <select id="dropdown" name="dropdown">
        <option value="0">Select</option>
        <option value="1">Critical Project Resource</option>
        <option value="2">Associate Unwilling to Travel</option>
    </select>
</label>
<label>Comments If Any  
<textarea name="comments" id="cmts"></textarea></label>
<br />
<br />
</div>
<input type="submit" id="sbt" value="Submit" name="Submit" onclick="javascript:InsertDetails();"/>
</fieldset>

This is the child window of the page.Here i'm using partial view also.i want to get all the values which are displayed in a page to be inserted into the table.can Anyone please help me out of this

rajeemcariazo
  • 2,476
  • 5
  • 36
  • 62
user2514925
  • 931
  • 8
  • 33
  • 56

2 Answers2

1

You should create a ViewModel for your view that will store your model and other data that you want to pass to your controller such as Supervisor Responses and Comments. Take advantage of the MVC extensions such as EditorFor, TextAreaFor, etc

Community
  • 1
  • 1
rajeemcariazo
  • 2,476
  • 5
  • 36
  • 62
  • 1
    A BeginForm will also need to be called here pointing back to Controller action decorated with HTTP Post. This is basic MVC stuff, I'd recommend looking at the tutorials: http://www.asp.net/mvc/tutorials – Pat Burke Jul 09 '13 at 13:30
0

Okay so what you have here is simply the View part of the Model-View-Controller. You seem to have a ViewModel for the list to display on the page, but you are still missing some key pieces:

  1. Another ViewModel to hold your form data you want to send to the Controller. Assuming you want to leave the structure of your View as is, you can simply add this new ViewModel as a property of your existing TravelReadyModel.
  2. Change your HTML form elements to use the HTML Helpers that end in "For" to auto-bind the values back to your new ViewModel. Surround these in an HTML.BeginForm().
  3. Add a controller method for the Post back of the data.
  4. Assuming that you have no DB backend support at all right now, use Entity Framework to setup the DB access.
  5. In the simplest form of a MVC application, the Controller will interact directly with the Entity Framework DataContext and add the newly posted ViewModel from the View to the DB.

There is a lot a research you are going to need to do here, but this should get you started. Here is a great comprehensive tutorial that will walk your through everything above and more! http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

Pat Burke
  • 580
  • 4
  • 13