Html.RadioButton sets all values to selected value - c#

After tinkering around to solve [this][1] problem, I think the core of the problem is the following:
When you use the Html.RadioButton() html helper with an Enum as value field, you can only choose your option once. AFter reposting the page, the helpers will ignore the value set in the call and set all radio buttons to the same value, being the value you selected the previous post back.
Am I doing something wrong?
Example (watch the value of the buttons)
<fieldset>
<legend>Test</legend>
<div>
<label for="SearchBag.EffectIndicatorAny" id="EffectIndicatorAnyLabel">
Any
</label>
<%=Html.RadioButton("SearchBag.EffectIndicator", "Any" , ViewData.Model.SearchBag.EffectIndicatorIsAny, new { #id = "SearchBag.EffectIndicatorAny" })%>
</div>
<div>
<label for="SearchBag.EffectIndicatorSolid" id="EffectIndicatorSolidLabel">
Solid
</label>
<%=Html.RadioButton("SearchBag.EffectIndicator", "Solid", ViewData.Model.SearchBag.EffectIndicatorIsSolid, new { #id = "SearchBag.EffectIndicatorSolid" })%>
</div>
<div>
<label for="SearchBag.EffectIndicatorEffect" id="EffectIndicatorEffectLabel">
Effect
</label>
<%=Html.RadioButton("SearchBag.EffectIndicator", "Effect", ViewData.Model.SearchBag.EffectIndicatorIsEffect, new { #id = "SearchBag.EffectIndicatorEffect" })%>
</div>
</fieldset>
Will generate
<fieldset>
<legend>Effect</legend>
<div class="horizontalRadio">
<label for="SearchBag.EffectIndicatorAny" id="EffectIndicatorAnyLabel">
Any
</label>
<input checked="checked" id="SearchBag.EffectIndicatorAny" name="SearchBag.EffectIndicator" type="radio" value="Any" />
</div>
<div class="horizontalRadio">
<label for="SearchBag.EffectIndicatorSolid" id="EffectIndicatorSolidLabel">
Solid
</label>
<input id="SearchBag.EffectIndicatorSolid" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
</div>
<div class="horizontalRadio">
<label for="SearchBag.EffectIndicatorEffect" id="EffectIndicatorEffectLabel">
Effect
</label>
<input id="SearchBag.EffectIndicatorEffect" name="SearchBag.EffectIndicator" type="radio" value="Effect" />
</div>
</fieldset>
And will generate the second time:
<fieldset>
<legend>Effect</legend>
<div class="horizontalRadio">
<label for="SearchBag.EffectIndicatorAny" id="EffectIndicatorAnyLabel">
Any
</label>
<input id="SearchBag.EffectIndicatorAny" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
</div>
<div class="horizontalRadio">
<label for="SearchBag.EffectIndicatorSolid" id="EffectIndicatorSolidLabel">
Solid
</label>
<input checked="checked" id="SearchBag.EffectIndicatorSolid" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
</div>
<div class="horizontalRadio">
<label for="SearchBag.EffectIndicatorEffect" id="EffectIndicatorEffectLabel">
Effect
</label>
<input id="SearchBag.EffectIndicatorEffect" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
</div>
</fieldset>

This is due to a bug in the ASP.NET MVC Beta code. I wrote a full explanation of the issue at asp.net MVC forum. Refer to this link

In case anybody cares here is a real quick and dirty work around in anticipation for the next update of the framework. It only regexreplaces the value with your value.
It's not unit tested, not guaranteed not whatever.
Put it in your HtmlHelper class library or wherever you put HtmlHelper extentions.
add the following usings:
System.Text.RegularExpressions;
System.Web.Mvc.Html;
/*ToDo: remove when patched in framework*/
public static string MonkeyPatchedRadio(this HtmlHelper htmlHelper, string name, object value, bool isChecked, object htmlAttributes){
string monkeyString = htmlHelper.RadioButton(name, value, isChecked, htmlAttributes);
monkeyString = Regex.Replace(monkeyString, "(?<=value=\").*(?=\".*)", value.ToString());
return monkeyString;
}
I know it can be done better and whatnot, but I really hope it will be fixed soon anyway.
If you feel like making it better, it's community wiki, so go ahead

One thing to check. Are you using the updated model to render your view? I.e. is the same model data that was updated from the post passed to the view the second time it's displayed?

Related

Rotativa form inline Bootstrap 4

I have a problem with Rotativa and Bootstrap. I want to generate a PDF with an inline form but it doesn't display inline. I've made a basic example. I am returning a PartialViewAsPdf and the html is a simple inline form example with bootstrap 4(w3schools). Any ideas?
.cshtml
<form class="form-inline" action="/action_page.php">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Controller
var actionPdf = new Rotativa.PartialViewAsPdf("File.cshtml", model);
return actionPdf
Expected result:
Actual Result
Rotativa doesn't know about display:flex.Replace this with display:-webkit-box.

Which format does ASP.NET expect when sending array with gaps?

This is my HTML:
<ul id="limitations" name="limitations" class="dropdown-menu">
<li>
<div class="checkbox checkbox-default">
<input type="checkbox" id="limitation-checkbox-0" value="8" name="limitations[0]" data-name="ALS ">
<label for="limitation-checkbox-0" style="color:black">ALS </label>
</div>
</li>
<li>
<div class="checkbox checkbox-primary">
<input type="checkbox" id="limitation-checkbox-1" value="10" name="limitations[1]" data-name="Arthrogryposis Multiplex Congenita (AMC) & Amyoplasia">
<label for="limitation-checkbox-1" style="color:black">Arthrogryposis Multiplex Congenita (AMC) & Amyoplasia</label>
</div>
</li>
<li>
<div class="checkbox checkbox-success">
<input type="checkbox" id="limitation-checkbox-2" value="2" name="limitations[2]" data-name="Cerebral Palsy (CP), (GMFS)">
<label for="limitation-checkbox-2" style="color:black">Cerebral Palsy (CP), (GMFS)</label>
</div>
</li>
<li>
<div class="checkbox checkbox-info">
<input type="checkbox" id="limitation-checkbox-3" value="4" name="limitations[3]" data-name="Hearing impairment deafness or hard of hearing">
<label for="limitation-checkbox-3" style="color:black">Hearing impairment deafness or hard of hearing</label>
</div>
</li>
... MORE <li> ...
</ul>
When I post the form, the model binder for List<int> limitations works only if the checkboxes are selected from, if there is a gap in the array, all items after the gap are not binded.
For example:
Consider the first(8) and the third(10) checkboxes are checked.
The value binded to List<int> limitations is [8].
Or if all the checkboxes are checked, List<int> limitations is binded witn an empty list.
I tried changing names of the checkboxes from name="limitations[0..n]" to name="limitations[]" but that caused ASP.NET to completely ignore the values.
Isn't there a standard for such things?!
I know how I can overcome this with javascript manipulation, but I really rather not going that awkward route for such a trivial case.
Using asp.net core 1.0.0 and .Net4.6.1
ASP.Net model binding hasn't changed this behavior between ASP.Net 4 and ASP.Net Core. The answer here is still valid.
Your naming convention is a little off. If you have multiple <input type="checkbox"...> with the same name, it should serialize automatically to the an array that ASP.Net's model binding can accommodate.
Try using name="limitations" instead of name="limitations[0]" throughout your inputs and see if that works as expected.

Submit form information to database based on radio button selection

Kinda lost in the sauce here...pretty green coming into the ASP.net realm, but have been enjoying my time in it so far.
So let me start from the beginning with this:
Background: I am working on a ASP.net MVC5 application with user login informtion. The user will create an account, recieve messages, etc. The critical component is that there will be a form on the site that allows the user to submit information in a Conditional Logic HTML Form complete with radio buttons, text areas and more. My end goal is to allow the user to fill out and submit the form, therefore submitting it to the MySQL database, sending an email to admin and the user with their selected elements and then populating their responses within their "Account Dashboard" area.
Problem: I am trying to get the user submitted information based on their radio button selection in the HTML Form, which would come in 3 different scenarios:
Web Project
2D Design Project
3D Design Project
So if the user chooses "Web" instead of "Graphic" in the "Project Type" form field, they would be submitting only values related to "Web". The problem I am running into is not being sure on the best way to accomplish this...
Here's the code I've started creating for when the user chooses a Web project for submission to the database:
if (IsPost) && (RadioButton.projectType.Equals(Web))
{
projectType = Request.Form["Web"];
TypeOfWebsite = Request.Form["TypeOfWebsite"];
DeviceExperience = Request.Form["DeviceExperience"];
}
Here is the form values:
<form method="post">
<br />
<div class="row">
<label class="formquestion col-md-3">Project Name:</label>
<input class="col-md-9" type="text" placeholder="Enter project name..." />
</div>
<div class="row">
<label id="ProjectType" for="ProjectType" class="formquestion col-md-3">Project Type: </label>
<span class="col-md-8">
<input id="Web" name="ProjectType" type="radio" value="#Request.Form["Web"] value=" web" />
<label for="Web">Web</label>
<input id="Graphic" name="ProjectType" type="radio" value="Graphic" />
<label for="Graphic">Graphic</label>
</span>
</div>
<div class="hidefield" id="WebProject">
<div class="row">
<label class="formquestion col-md-3">Type Of Website: </label>
<span class="col-md-8">
<input id="WebApplication" name="TypeOfWebsite" type="radio" value="1" />
<label class="Web Application" for="Web Application">Web Application*</label>
<input id="eCommerce" name="TypeOfWebsite" type="radio" />
<label class="choice" for="eCommerce">eCommerce</label>
<input id="SocialNetwork" name="TypeOfWebsite" type="radio" />
<label class="choice" for="SocialNetwork">Social Network</label>
<input id="Forum" name="TypeOfWebsite" type="radio" />
<label class="choice" for="Forum">Forum</label>
<input id="PackageDesign" name="TypeOfWebsite" type="radio" />
<label class="choice" for="PackageDesign">News/Article</label>
<input id="Interactive" name="TypeOfWebsite" type="radio" />
<label class="choice" for="Interactive">Interactive</label>
<input id="InformationalPersonal" name="TypeOfWebsite" type="radio" />
<label class="choice" for="InformationalPersonal">Informational/Personal</label>
<p>*Not exactly sure what a web application is? Well...think TurboTax, Zamzar, Mint, Online Banking Services, MailChimp and Google Docs. </p>
</span>
</div>
<div class="row">
<label class="formquestion col-md-3" for="DeviceExperience">Device Experience: </label>
<span class="col-md-8">
<input id="Desktop" name="DeviceExperience" type="radio" value="1" />
<label for="Desktop">Desktop</label>
<input id="Tablet" name="DeviceExperience" type="radio" />
<label for="Tablet">Tablet</label>
<input id="Mobile" name="DeviceExperience" type="radio" />
<label for="Mobile">Mobile</label>
<input id="Responsive" name="DeviceExperience" type="radio" />
<label for="Responsive">Responsive</label>
</span>
</div>
</div>
<div class="hidefield" id="GraphicDimensions">
<div class="row">
<label class="formquestion col-md-3">Design Dimensions: </label>
<span class="col-md-8">
<input id="2D" name="Dimension" type="radio" value="2D" />
<label class="choice" for="Web">2D</label>
<input id="3D" name="Dimension" type="radio" value="3D" />
<label for="3D">3D</label>
</span>
</div>
</div>
<div class="hidefield" id="2DGraphicProject">
<div class="row">
<label class="formquestion col-md-3">Choose 2D Design: </label>
<span class="col-md-8">
<input id="BusinessCard" name="2DDesign" type="radio" value="1" />
<label class="BusinessCard" for="BusinessCard">Business Card</label>
<input id="Flyer" name="2DDesign" type="radio" />
<label class="choice" for="Flyer">Flyer</label>
<input id="Poster" name="2DDesign" type="radio" />
<label class="choice" for="Poster">Poster</label>
<input id="PrintAd" name="2DDesign" type="radio" />
<label class="choice" for="PrintAd">Print Ad</label>
<input id="PackageDesign" name="2DDesign" type="radio" />
<label class="choice" for="PackageDesign">Package Design (Food/Product/Media)</label>
<input id="Logo" name="Logo" type="radio" />
<label class="choice" for="Logo">Logo</label>
</span>
</div>
</div>
<div class="hidefield" id="hide3DDesignExplaination">
<div class="row">
<label class="formquestion col-md-3" for="3DDesign">Explain this 3D Design project: </label>
<textarea id="3DDesignExplaination" name="3DDesignExplaination" class="textareaform"></textarea>
</div>
</div>
<div class="hidefield" id="ProjectObjective">
<div class="row">
<label class="formquestion col-md-3" for="Objective">Project Objective:</label>
<textarea id="ObjectiveExplaination" name="ObjectiveExplaination" class="textareaform" placeholder="What is this website's primary objective? Sell me on it!"></textarea>
</div>
</div>
<div class="hidefield" id="DesignCopy">
<div class="row">
<label class="formquestion col-md-3" for="DesignCopy">Design Copy </label>
<textarea id="DesignCopy" name="DesignCopy" class="textareaform" placeholder="Any messeging/text/info needed to be included?"></textarea>
</div>
</div>
<div class="hidefield" id="TargetAudience">
<div class="row">
<label class="formquestion col-md-3" for="TargetAudience">Describe Your Target Audience:</label>
<textarea id="TargetAudienceExplaination" name="TargetAudienceExplaination" class="textareaform" placeholder="Who is your target audience? What are their ages? What do they do for a living? Elaborate!"></textarea>
</div>
</div>
<div class="hidefield" id="Keywords">
<div class="row">
<label class="formquestion col-md-3">Keywords To Describe This Project:</label>
<input class="col-md-9" type="text" placeholder="Give me 3 keywords!">
</div>
</div>
<div class="hidefield" id="FirstInteraction">
<div class="row">
<label class="formquestion col-md-3" for="UserFirstInteraction">User First Interaction:</label>
<textarea id="UserFirstInteraction" name="UserFirstInteraction" class="textareaform" placeholder="What Should The User Do First Upon Visiting The Website?"></textarea>
</div>
</div>
<div class="hidefield" id="General2">
<div class="row">
<label class="formquestion col-md-3" for="FavoriteColors">3 Favorite Colors?</label>
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow">
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow">
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow">
<small>Hint: you can type in any CSS color (even named ones, like yellow).</small>
</p>
</div>
<div class="hidefield" id="Necessities">
<div class="row">
<label class="formquestion col-md-3" for="UserFirstInteraction">Necessities:</label>
<textarea id="DesignCopy" name="ProjectReason" class="textareaform" placeholder="What are necessities for this project? Specific graphic/sitefunctionalities?"></textarea>
</div>
</div>
<h5 class="bkgblack center-align col-md-11">Provide URL's of Site/Graphics (whatever is applicable) that design you admire</h5>
<div class="row">
<label class="formquestion col-md-3" for="AdmireURL1">URL #1: </label>
<input id="AdmireURL1" name="AdmireURL1" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="AdmireURL2">URL #2: </label>
<input id="AdmireURL2" name="AdmireURL2" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="AdmireURL3">URL #3: </label>
<input id="AdmireURL3" name="AdmireURL3" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="hidefield" id="RivalURL">
<h5 class="bkgblack center-align col-md-11">Provide URL's for "competitor" sites:</h5>
<div class="row">
<label class="formquestion col-md-3" for="RivalURL1">Rival URL #1: </label>
<input id="RivalURL1" name="RivalURL1" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="RivalURL2">Rival URL #2: </label>
<input id="RivalURL2" name="RivalURL2" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="RivalURL3">Rival URL #3: </label>
<input id="RivalURL3" name="RivalURL3" type="text" maxlength="255" title="" value="http://" />
</div>
</div>
</div>
<br />
<div class="hidefield" id="ProjectReason">
<div class="row">
<label class="formquestion col-md-3" for="UserFirstInteraction">Project Reason:</label>
<textarea id="DesignCopy" name="ProjectReason" class="textareaform" placeholder="Why does your target audience NEED this project to exist?"></textarea>
</div>
</div>
<div class="row">
<form action="file-upload.php" class="dropzone"></form>
</div>
<button type="submit" name="SubmitForm" class="btn btn-info btn-large">Submit Form</button>
</form>
The various MSDN tutorials I have been looking at to better understand:
http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/form-basics
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobutton.aspx
These tutorials haven't made it clear to me on how to create these essential 3 conditional statements for my form:
"If user has chosen Project Type = "Web" and submitted the form, send (insert form variables) to the database"
"If user has chosen Project Type = "Graphic" then Dimension = "2D" and submitted the form, send (insert relative values) to the database"
"If user has chosen Project Type = "Graphic", then Dimension = "3D" and submitted the form, send (insert relative values)" to the database"
Recap:
How do I write the conditional statement to accomplish this?
Should I reconsider the HTML form format I am using in favor of ASP Web Pages?
I have written some JavaScript to show the available form values based upon user selection to follow this schema using the "value" of each field. It works just as intended! Now I'm just trying to connect dots on how to submit this information to the database so I can use it in the user profile. Any thoughts/answers would be greatly welcomed!
That's a complex form. But, for the sake of simplicity I will reduce the number of fields in your form to give you an idea of how things are the MVC way.
I'll start by pointing out that you are not taking the full advantage of MVC. It stands for Model-View-Controller, which is a design pattern. You probably know that stuff, but, I don't see a hint in your code that tells me you are using models in your project, you don't have to...but since you are starting with MVC you should. So, suppose you have the following models...
public class ProjectTypeModel
{
public string Name { get; set; }
}
public class TestModel
{
public IList<ProjectTypeModel> Types { get; set; }
}
Then you're view declares that same model...
#model MvcTest.Models.TestModel
This goes on the top of the view file, the first line of code. The simplified form would look like this...
#using(Html.BeginForm("ProcessTypes","Home")){
<div class="row">
<label class="formquestion col-md-3">Project Type: </label>
<span class="col-md-8">
#foreach (var p in Model.Types)
{
<input id="#("radio_" + p.Name)" type="radio" name="SelectedProjectType" value="#p.Name" />
<label for="#("radio_" + p.Name)">#p.Name</label>
}
</span>
</div>
<input type="submit" name="SubmitForm" class="btn btn-info btn-large" value="Submit Form" />
}
The only thing to note here is that the radio buttons MUST have the same name. The id is not too relevant, just make them unique so you can set the label's for attribute, this way when you click the label the radio button will change its state. The last thing to notice is the form is posting to the "ProcessTypes" action of the Home controller...
and your Home controller's action will look something similar to this...
public ActionResult ProcessTypes(string SelectedProjectType)
{
//processing here...
}
Obviously, the SelectedProjectType will have come with the value of the radio button you selected..."Web" or "Design".
Even though this is a very simplified example you can get an idea of how things work in MVC (and Razor). There's a bit more to cover but I'm sure you will find out by yourself.
Hope it makes sense

Form post to another page

I am fairly new to C# and asp.net and am having trouble showing something submitted in a form. The form element is a tag. The drop-down info is pulled from a data base and displays correctly. It's just getting it to post to another page after the form is submitted is where I am having the problem. Any help would be appreciated.
Contact.aspx:
<form action="Default.aspx" method="post" data-transition="pop">
<div data-role="fieldcontain">
<label for="topEmails">Business Entity ID:</label>
<select name="topEmails" id="topEmails" data-native-menu="false"
runat="server">
</select>
</div>
<input type="submit" data-iconpos="right" data-inline="true"
data-icon="plus" name="sendMessage" id="sendMessage" value="Send Info">
</form>
Contact.aspx.cs:
AdventureWorks2012DataContext db = new AdventureWorks2012DataContext();
var emails = (from b in db.EmailAddresses
select new { b.EmailAddressID, b.BusinessEntityID }).Take(20);
topEmails.DataTextField = "BusinessEntityID";
topEmails.DataValueField = "BusinessEntityID";
topEmails.DataSource = emails;
topEmails.DataBind();
Default.aspx.cs:
FormSuccessBID.InnerHtml = "Business Entity ID: " + Request.Form["topEmails"] + "";
Any ideas why this wouldn't be working?
Update:
Contact.aspx:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h2 style="text-align: center;">Contact Kyle</h2>
<form action="Default.aspx" method="post" data-transition="pop">
<div data-role="fieldcontain">
<label for="userFName">First Name:</label>
<input type="text" name="firstName" id="uFName">
</div>
<div data-role="fieldcontain">
<label for="userLName">Last Name :</label>
<input type="text" name="lastName" id="uLName">
</div>
<div data-role="fieldcontain">
<label for="productsCategories">Products:</label>
<select name="productCategories" id="productCategories" data-native-menu="false" runat="server"></select>
</div>
<div data-role="fieldcontain">
<label for="topEmails">Business Entity ID:</label>
<select name="topEmails" id="topEmails" data-native-menu="false" runat="server"></select>
</div>
<input type="submit" data-iconpos="right" data-inline="true" data-icon="plus" name="sendMessage" id="sendMessage" value="Send Info">
</form>
</asp:Content>
You're missing "runat='server'" in your form definition.
In ASP.NET you're also allowed one form per page. Not sure from what you're posted if you're trying to put multiple forms on there, but if you are, it's not going to work.
I think all you need to do to accomplish what you want is have an ASP.NET button on the page, with the postbackURL set to the page you want to go to. (Of course, you need to do this in a server-side form)
I think you're mixing ASP.NET methods with other, different technologies. (From the look of it, you probably used classic ASP or PHP perhaps?)
If you can't use .NET for whatever reason, the ID/name of the field is not going to be what you're expecting. You need to inspect the form post and find its value - something along the lines of "clt00_somethingelse_topEmails". (Again, this is going to be a heck of a lot easier if you use the .NET way of doing things, but you may have a requirement not to)

How to Insert the values displayed in viewpage to backend

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
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
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:
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.
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().
Add a controller method for the Post back of the data.
Assuming that you have no DB backend support at all right now, use Entity Framework to setup the DB access.
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

Categories

Resources