Just need to know how to append this entire html on a button click. I'm trying to create a list and display it over the page. .......................................................................................................................................
#Html.BeginForm(null, null, FormMethod.Get, new { name = "vouchers", id = "vouchers" })
<h2>Voucher</h2>
<div class="whole">
<div class ="top">
<label class ="lbl" >Assign a voucher Number </label>
<input type ="text" class="txt"/>
</div>
<div class="mid">
<div class ="tdes">
<table class="vtab">
<tr class="heading">
<td>
Date
</td>
<td>
Name
</td>
<td>
Category
</td>
<td>
Amount
</td>
<td>
To Account
</td>
</tr>
#foreach (var item in Model) {
<tr class="rows">
<td>
#item.Date.ToShortDateString()
</td>
<td>
#Html.DisplayFor(modelItem => item.Per)
</td>
<td>
#Html.DisplayFor(modelItem => item.CId)
</td>
<td>
#Html.DisplayFor(modelItem => item.Amt)
</td>
<td>
#Html.DisplayFor(modelItem => item.AId)
</td>
</tr>
}
</table>
</div>
</div>
<div class="bot">
<input type ="submit" value="Save" class ="btn" id ="save" />
<input type ="submit" value ="Print" class="btn" id ="print" />
</div>
</div>
}
How about using jQuery UI Dialog:
$("#vouchers").dialog({
autoShow: false,
// Other options
});
$("#somebutton").click(function() {
$("#vouchers").dialog("show");
});
Related
I have a scenario where i have 3 radio buttons two of them have default values and for the third one I want that it should be assigned the value of a textbox. How can I achieve this below is some of my code :
<tr>
<td>
<label style="padding-bottom:0.5em;font-size:1em">
#Html.RadioButtonFor(model => model.LicenseValidityDuration, "0", new { style = "width:2em" })
Never
</label>
</td>
<td></td>
</tr>
<tr>
<td>
<label style="padding-bottom:0.5em;font-size:1em">
#Html.RadioButtonFor(model => model.LicenseValidityDuration, "-1", new { style = "width:2em" })
Always
</label>
</td>
<td></td>
</tr>
<tr>
<td>
<label style="padding-bottom:0.5em;font-size:1em">
#Html.RadioButtonFor(model => model.LicenseValidityDuration, model => model.LicenseValidityDuration, new { style = "width:2em" })
Days Before Expiry
</label>
</td>
<td>
#Html.EditorFor(model => model.LicenseValidityDuration)
</td>
</tr>
I want to don't bind my dropdown list if the form state is post back. As you can see in my code I have two forms and two submit buttons. I want to keep selected value of dropdownlist after I click second submit button.
<form method="POST" action="#Url.Action("UserRoles", "PageUserRole")">
<label>Kullanıcı Grubu</label>
#Html.DropDownList("Id", Utility.GetUserGroups(), "Kullanıcı Grubu Seçiniz.")
<input type="submit" value="Listele" />
</form>
....
<form method="POST" action="#Url.Action("EditUserRoles", "PageUserRole")">
<table>
<tbody>
<tr>
<td>
İşlem
</td>
<td>
Yetki
</td>
</tr>
#for (int i = 0; i < Model.PageMenUsuserRoles.Count; i++)
{
<tr>
<td>
#Model.PageMenUsuserRoles[i].pagemenu.Name
</td>
<td>
#Html.Hidden("PageMenUsuserRoles[" + i + "].Id", Model.PageMenUsuserRoles[i].Id)
#Html.CheckBox("PageMenUsuserRoles[" + i + "].CanView", Model.PageMenUsuserRoles[i].CanView)
</td>
</tr>
}
<tr>
<td colspan="2">
<input type="submit" value="Kaydet" />
</td>
</tr>
</tbody>
</table>
</form>
I have a form which is submitted via ajax to the Controller. The Controller collects the data from the Model and then creates a new ViewModel and passes it to the partial view which is then updated on the Client.
The problem is that the textboxes are not cleared out as expected. The message arrives in the View as expected, so it doesn't make sense that the TextBoxes are not cleared out.
Yet it seems to be a browser issue as this is the resulting HTML, which note, does not have anything in the value:
<input id="Address_Address1" name="Address.Address1" type="text" value="" />
Yet the user sees the value that was priorly entered.
Here is the controller:
//Process Order Here
//This should clear out the ViewModel.
order = new OrderViewModel();
order.Message = "Report Added to your cart";
return PartialView("_NewOrderPartial", order);
This is the partial View:
#model NTC.PropertySearch.Models.OrderViewModel
#using (Ajax.BeginForm("NewOrder", "Order", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "neworder" }))
{
<div id="neworder">
<table>
<tr>
<th style="width: 300px;">
<h3>Enter property address below</h3>
</th>
<th style="width: 30px;"></th>
<th style="width: 300px;">
<h3>Choose your report below</h3>
</th>
</tr>
<tr>
<td>
<div class="form">
<table>
<tr>
<td>
#Html.LabelFor(m => m.Address.Address1)
</td>
<td>
#Html.TextBoxFor(m => m.Address.Address1)
</td>
<td>
#Html.ValidationMessageFor(m => m.Address.Address1)
</td>
</tr>
<tr>
<td>
#Html.LabelFor(m => m.Address.Address2)
</td>
<td>
#Html.TextBoxFor(m => m.Address.Address2)
</td>
<td>
#Html.ValidationMessageFor(m => m.Address.Address2)
</td>
</tr>
<tr>
<td>
#Html.LabelFor(m => m.Address.City)
</td>
<td>
#Html.TextBoxFor(m => m.Address.City)
</td>
<td>
#Html.ValidationMessageFor(m => m.Address.City)
</td>
</tr>
<tr>
<td>
#Html.LabelFor(m => m.Address.State)
</td>
<td>
#Html.TextBoxFor(m => m.Address.State)
</td>
<td>
#Html.ValidationMessageFor(m => m.Address.State)
</td>
</tr>
<tr>
<td>
#Html.LabelFor(m => m.Address.ZipCode)
</td>
<td>
#Html.TextBoxFor(m => m.Address.ZipCode)
</td>
<td>
#Html.ValidationMessageFor(m => m.Address.ZipCode)
</td>
</tr>
</table>
<input type="submit" value="Add Report" />
#Html.DisplayFor(m=> m.Message)
</div>
</td>
</tr>
</table>
</div>
The reason for this is because the Html helpers such as TextBox are first looking at the ModelState when binding their values and only after that in the View model. This often happens when people attempt to modify/clear some value to the view model in an HttpPost controller action. The corresponding view will use the initial POSTed value and not the value in the view model.
You should clear the ModelState as well in your controller action:
ModelState.Clear();
order = new OrderViewModel();
Alternatively if you do not want to clear the entire ModelState (although in your case this seems to be the case as you are reinitializing the entire view model) you could clear only some properties that you intend to modify:
ModelState.Remove("SomeProperty");
viewModel.SomeProperty = "some new value";
I am working on asp.net MVC 2 application. I have a form like this:
<% using (Html.BeginForm("UpdateRecordingDetails", "Recording", FormMethod.Post, new { id = "frmRecordingEdit" }))
{%>
<%= Html.Hidden("AccountIDsEdit", ViewData["AccountIDsEdit"]) %>
<%= Html.Hidden("SelId", ViewData["SelId"]) %>
<%= Html.Hidden("EditMode", ViewData["EditMode"]) %>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr valign="top">
<td>
<table align="center">
<tr>
<td style="width: 32%;">
<%=Html.HiddenFor(model=>model.Id) %>
<b>Person Name</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.PersonName, new { #class = "textarea wide" , disabled ="disabled"})%>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Email</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.Email, new { #class = "textarea wide" })%>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Notes</b>
</td>
<td>
<%: Html.TextAreaFor(model => model.Notes, new { #class = "textarea widetextarea" })%>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Display Notes on Playback</b>
</td>
<td>
<%: Html.DropDownList("isNotesVisible", ViewData["displayNotes"] as SelectList, new {#class = "normal" })%>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Call ID Number</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CallIDNumber, new { #class = "textarea normal", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Dblink Unique URL</b>
</td>
<td>
<span id="DBLinkUniqueURL" class="small">
<%= Model.DBLinkUniqueURL %>
</span>
<input id="btnCopy" type="button" value="Copy to Clipboard" onclick="copyToClipboard('DBLinkUniqueURL')" />
</td>
</tr>
<tr>
<td>
<b>Call Password</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CallPassword, new { #class = "textarea wide", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Number Called</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.NumberCalledFrom, new { #class = "textarea wide", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Called From</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.NumberCalledTo, new { #class = "textarea wide", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Call Duration</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CallDuration, new { #class = "textarea normal", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Call Rate</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CallRate, new { #class = "textarea normal", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Call Cost</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CallCost, new { #class = "textarea tiny", disabled = "disabled" })%>
<%: Html.TextBoxFor(model => model.CallCost, new { #class = "textarea normal", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>User ID/ Email</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.LoginId, new { #class = "textarea wide", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Date/Time Added</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CreationDate, new { #class = "textarea wide", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Call Status</b>
</td>
<td>
<%: Html.TextBoxFor(model => model.CallStatus, new { #class = "textarea normal", disabled = "disabled" })%>
</td>
</tr>
<tr>
<td>
<b>Archived</b>
</td>
<td>
<%: Html.CheckBoxFor(model => model.isArchived, new { disabled = "disabled"})%>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
}
%>
I have a button outside this form, which posts the form with jquery ajax like this:
function editAccountDetails() {
jQuery.ajax({
url: "/recording/UpdateRecordingDetails",
type: 'POST',
data: $('frmRecordingEdit').serialize(),
dataType: "json",
contentType: "application/json",
success: function (data) {
alert(data);
}
});
}
In controller action method, I am not getting all these fields. I get only the ones which are in viewdata or which are not disabled and checkbox value. My action method is:
[Authorize]
public ActionResult UpdateRecordingDetails(FormCollection form, CallRecordingModel objCampaignMode)
{
return Content("testing");
}
neither formcollection note the model has all the fields values which are in the form.
[Edit]
form has values for
AccountIDsEdit
SelId
EditMode
Id
Email
Notes
isNotesVisible
isArchived
model has values in three fields
email, Id, notes
<td>
<table align="center">
<tbody><tr>
<td style="width: 32%;">
<input type="hidden" value="2" name="Id" id="Id">
<b>Person Name</b>
</td>
<td>
<input type="text" value="Asif" readonly="readonly" name="PersonName" id="PersonName" disabled="disabled" class="textarea wide">
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Email</b>
</td>
<td>
<input type="text" value="asif#cc.com" name="Email" id="Email" class="textarea wide">
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Notes</b>
</td>
<td>
<textarea rows="2" name="Notes" id="Notes" cols="20" class="textarea widetextarea">asif notes</textarea>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Display Notes on Playback</b>
</td>
<td>
<select name="isNotesVisible" id="isNotesVisible" class="normal"><option selected="selected">Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Call ID Number</b>
</td>
<td>
<input type="text" value="callIDNum002" name="CallIDNumber" id="CallIDNumber" disabled="disabled" class="textarea normal">
</td>
</tr>
<tr>
<td style="width: 32%;">
<b>Dblink Unique URL</b>
</td>
<td>
<span class="small" id="DBLinkUniqueURL">
http://temp.com/callIDNum002
</span>
<input type="button" onclick="copyToClipboard('DBLinkUniqueURL')" value="Copy to Clipboard" id="btnCopy">
</td>
</tr>
<tr>
<td>
<b>Call Password</b>
</td>
<td>
<input type="text" value="temppass" name="CallPassword" id="CallPassword" disabled="disabled" class="textarea wide">
</td>
</tr>
<tr>
<td>
<b>Number Called</b>
</td>
<td>
<input type="text" value="03344037289" name="NumberCalledFrom" id="NumberCalledFrom" disabled="disabled" class="textarea wide">
</td>
</tr>
<tr>
<td>
<b>Called From</b>
</td>
<td>
<input type="text" value="0442510406" name="NumberCalledTo" id="NumberCalledTo" disabled="disabled" class="textarea wide">
</td>
</tr>
<tr>
<td>
<b>Call Duration</b>
</td>
<td>
<input type="text" value="00:01:30" name="CallDuration" id="CallDuration" disabled="disabled" class="textarea normal">
</td>
</tr>
<tr>
<td>
<b>Call Rate</b>
</td>
<td>
<input type="text" value="4" name="CallRate" id="CallRate" disabled="disabled" class="textarea normal">
</td>
</tr>
<tr>
<td>
<b>Call Cost</b>
</td>
<td>
<input type="text" value="3" name="CallCost" id="CallCost" disabled="disabled" class="textarea tiny">
<input type="text" value="3" name="CallCost" id="CallCost" disabled="disabled" class="textarea normal">
</td>
</tr>
<tr>
<td>
<b>User ID/ Email</b>
</td>
<td>
<input type="text" value="asif_hameed_371#hotmail.com" name="LoginId" id="LoginId" disabled="disabled" class="textarea wide">
</td>
</tr>
<tr>
<td>
<b>Date/Time Added</b>
</td>
<td>
<input type="text" value="12/19/2012 12:00:00 AM" name="CreationDate" id="CreationDate" disabled="disabled" class="textarea wide">
</td>
</tr>
<tr>
<td>
<b>Call Status</b>
</td>
<td>
<input type="text" value="Completed" name="CallStatus" id="CallStatus" disabled="disabled" class="textarea normal">
</td>
</tr>
<tr>
<td>
<b>Archived</b>
</td>
<td>
<input type="checkbox" value="true" name="isArchived" id="isArchived" disabled="disabled"><input type="hidden" value="false" name="isArchived">
</td>
</tr>
</tbody></table>
</td>
[Edit2]
Request URL:http://localhost:62843/recording/UpdateRecordingDetails
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:0
Content-Type:application/json
Cookie:SiteBrowsedCookie=1;edited value&FirstVisit=9/14/2012 5:42:08 PM; Nop.customer=61f1bf57-034a-4427-a08c-e9442061f224; glimpseState=null; glimpseClientName=null; glimpseOptions=null; ASP.NET_SessionId=lephqzclxx35mjqier5to5l4; .CRM=85A97958C0415B3C8106A7EE2B473EE00C1F53C5E428C399AC951D7AFEA5A325C8BC54225AC959917CF1754734CF8DC6BD13DAAA7DA1EE64D4A177BB3FA3529992A1E596AF6D1D4391242C412EB809F8125EC03DBC1C5A36FDAE3BAB915E2233C30E0876EFE62B3D8CAE1CCAD020DA6791EA17FD3B085C1A913C8DBF822408FD0E2AA3B19F67AFE34C9176A3783F0935D61B847D51958ABB72AB2E9491864F956A90729E; returnUrl=returnUrl=http://localhost:62843/Account/Login
Host:localhost:62843
Origin:http://localhost:62843
Referer:http://localhost:62843/Recording/Detail
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
X-Requested-With:XMLHttpRequest
Response Headersview source
Cache-Control:private, s-maxage=0
Connection:Close
Content-Length:8
Content-Type:text/html; charset=utf-8
Date:Fri, 21 Dec 2012 07:16:02 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
Please suggest solution to it.
data: $('frmRecordingEdit').serialize(),
should be:
data: $('#frmRecordingEdit').serialize(),
because that's how id selectors work in jQuery.
Also you haven't shown how/where you are calling the editAccountDetails function that is sending the AJAX request but if this is inside an onsubmit handler of the form or an onclick handler of a submit button of this form or an onclick handler of some anchor you should make sure that you return false from this handler to ensure that you are cancelling the default action and giving chance of the AJAX call to execute. If you do not cancel the default action the browser will simply redirect away from the page leaving no chance of any AJAX calls to execute.
During debugging, my MVC model and Formcollection are blank with no values in FireFox (15) or Chrome (latest version).
During debugging using IE (9), I can see these values just fine.
Do you know what the solution is for this? This is very serious for public facing web sites not being able to do any programming angainst these browsers.
Here is my View...
#model PDFConverterModel.ViewModels.ViewModelTemplate_Guarantors
#{
ViewBag.Title = "BHG :: PDF Generator";
}
<h2>#ViewBag.Message</h2>
<div>
<table style="width: 1000px">
<tr>
<td colspan="5">
<img alt="BHG Logo" src="~/Images/logo.gif" />
</td>
</tr>
#using (Html.BeginForm("ProcessForm", "Home", FormMethod.Post))
{
<tr>
<td>
#(Html.Kendo().IntegerTextBox()
.Name("LoanID")
.Placeholder("Enter Loan ID")
)
</tr>
<tr>
<td>#Html.LabelFor(model => model.LoanType)
#Html.DisplayFor(model => model.LoanType)
</td>
<td>
<label for="ddlDept">Department:</label>
#(Html.Kendo().DropDownList()
.Name("ddlDept")
.DataTextField("DepartmentName")
.DataValueField("DepartmentID")
.Events(e => e.Change("Refresh"))
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetDepartments", "Home");
});
})
)
</td>
</tr>
if (Model.ShowGeneratePDFBtn == true)
{
if (Model.ErrorT == string.Empty)
{
<tr>
<td colspan="5">
<u><b>#Html.Label("Templates:")</b></u>
</td>
</tr>
<tr>
#for (int i = 0; i < Model.Templates.Count; i++)
{
<td>
#Html.CheckBoxFor(model => Model.Templates[i].IsChecked)
#Html.DisplayFor(model => Model.Templates[i].TemplateId)
</td>
}
</tr>
}
else
{
<tr>
<td>
<b>#Html.DisplayFor(model => Model.ErrorT)</b>
</td>
</tr>
}
if (Model.ErrorG == string.Empty)
{
<tr>
<td colspan="5">
<u><b>#Html.Label("Guarantors:")</b></u>
</td>
</tr>
<tr>
#for (int i = 0; i < Model.Guarantors.Count; i++)
{
<td>
#Html.CheckBoxFor(model => Model.Guarantors[i].isChecked)
#Html.DisplayFor(model => Model.Guarantors[i].GuarantorFirstName) #Html.DisplayFor(model => Model.Guarantors[i].GuarantorLastName)
</td>
}
</tr>
}
else
{
<tr>
<td>
<b>#Html.DisplayFor(model => Model.ErrorG)</b>
</td>
</tr>
}
}
<tr>
<td colspan="3">
<input type="submit" name="submitbutton" id="btnRefresh" value='Refresh' />
</td>
#if (Model.ShowGeneratePDFBtn == true)
{
<td>
<input type="submit" name="submitbutton" id="btnGeneratePDF" value='Generate PDF' />
</td>
}
</tr>
<tr>
<td colspan="5">
#Model.Error
</td>
</tr>
}
</table>
</div>
<script type="text/javascript">
$('btnRefresh').on('click', '#btnRefresh', function () {
Refresh();
});
function Refresh() {
var LoanID = $("#LoanID").val();
if (LoanID != "") {
document.forms[0].submit();
}
else {
alert("Please enter a LoanId");
}
}
</script>
I know this is a very old question, but answering this might help people like who are struggling with this issue.
I had a similar issue. The problem lies here:
<table style="width: 1000px">
<tr>
<td colspan="5">
<img alt="BHG Logo" src="~/Images/logo.gif" />
</td>
</tr>
#using (Html.BeginForm("ProcessForm", "Home", FormMethod.Post))
{
<tr>
<td>
#(Html.Kendo().IntegerTextBox()
.Name("LoanID")
.Placeholder("Enter Loan ID")
)
</td>
</tr>
}
</table>
After begin form there are <tr> tags directly! Browsers like chrome and mozilla get confused in such cases. The <table> tag should be inside the form. If we look at your code, which was exactly what I had done, <table> tag was before #using Html.BeginForm.
Internet Explorer somehow understands this, but the other browsers don't.
When I did an inspect element I found that there was a form tag within each <tr> tag and it always returned FormCollection as null. Simply defining <table> within form solved my problem.
So here's how it should be:
<table style="width: 1000px">
<tr>
<td colspan="5">
<img alt="BHG Logo" src="~/Images/logo.gif" />
</td>
</tr>
<tr><td>
#using (Html.BeginForm("ProcessForm", "Home", FormMethod.Post))
{
<table>
<tr>
<td>
#(Html.Kendo().IntegerTextBox()
.Name("LoanID")
.Placeholder("Enter Loan ID")
)
</td>
</tr>
</table>
}
</td></tr>
</table>
I just found out what the issue is by experimneting.
The Telerik MVC widgets don't emit any FormCollection data!!!!
Only EditorFor and TextBoxFor emit these values, plus the input buttons.
What good are these widgets if I can't use the FormCollection values from them???? Especially the DropDownList where I can retrireve data and need the selected value to pass onto other methods.
(This would be better suited as comment, but I can't comment yet)
For future reference, here's a spec (W3C might have something different) for what gets submitted when a form is submitted:
http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#category-submit
You can look at whatever HTML was generated to make sure it gets submitted. You could also use something like Fiddler to look at the Http request