I'm trying to render a partial ascx view within another view.
I have the following error however in my ascx file, and after some research I'm still in the dark!:
Type or namespace definition, or
end-of-file expectedend-of-file expected
Here is the code in DinnerForm.ascx
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>
<%: Html.ValidationSummary("Please Corrent the Errors and Try Again.") %>
<fieldset>
<legend>Fields</legend>
<table border="0">
<tr>
<td><%: Html.LabelFor(m => m.Title) %></td>
<td><%: Html.TextBoxFor(m => m.Title) %></td>
<td><%: Html.ValidationMessageFor(m => m.Title, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.EventDate) %></td>
<td><%: Html.TextBoxFor(m => m.EventDate) %></td>
<td><%: Html.ValidationMessageFor(m => m.EventDate, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Description) %></td>
<td><%: Html.TextAreaFor(m => m.Description) %></td>
<td><%: Html.ValidationMessageFor(m => m.Description, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Address) %></td>
<td><%: Html.TextBoxFor(m => m.Address) %></td>
<td><%: Html.ValidationMessageFor(m => m.Address, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Country) %></td>
<td><%: Html.DropDownListFor(m => m.Country, ViewData["countries"] as SelectList)%></td>
<td><%: Html.ValidationMessageFor(m => m.Country, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.ContactPhone) %></td>
<td><%: Html.TextBoxFor(m => m.ContactPhone) %></td>
<td><%: Html.ValidationMessageFor(m => m.ContactPhone, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Latitude) %></td>
<td><%: Html.TextBoxFor(m => m.Latitude) %></td>
<td><%: Html.ValidationMessageFor(m => m.Latitude, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Longitude) %></td>
<td><%: Html.TextBoxFor(m => m.Longitude) %></td>
<td><%: Html.ValidationMessageFor(m => m.Longitude, "*") %></td>
</tr>
<tr>
<td><input type ="submit" value="Save" /></td>
</tr>
</table>
</fieldset>
<% } %>
And here is an example of how I am using it in a file called create.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Models.Dinner>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Host a Dinner
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Host a Dinner</h2>
<% Html.RenderPartial("DinnerForm"); %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
Notice how you have <% } %> at the bottom of the .ascx file? That is a closing bracket for <% using (Html.BeginForm()) {%> which you seem to have missed out.
Add
<% using (Html.BeginForm()) {%>
to just below the
<%: Html.ValidationSummary("Please Corrent the Errors and Try Again.") %>
Resulting form
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>
<%: Html.ValidationSummary("Please Corrent the Errors and Try Again.") %>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<table border="0">
<tr>
<td><%: Html.LabelFor(m => m.Title) %></td>
<td><%: Html.TextBoxFor(m => m.Title) %></td>
<td><%: Html.ValidationMessageFor(m => m.Title, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.EventDate) %></td>
<td><%: Html.TextBoxFor(m => m.EventDate) %></td>
<td><%: Html.ValidationMessageFor(m => m.EventDate, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Description) %></td>
<td><%: Html.TextAreaFor(m => m.Description) %></td>
<td><%: Html.ValidationMessageFor(m => m.Description, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Address) %></td>
<td><%: Html.TextBoxFor(m => m.Address) %></td>
<td><%: Html.ValidationMessageFor(m => m.Address, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Country) %></td>
<td><%: Html.DropDownListFor(m => m.Country, ViewData["countries"] as SelectList)%></td>
<td><%: Html.ValidationMessageFor(m => m.Country, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.ContactPhone) %></td>
<td><%: Html.TextBoxFor(m => m.ContactPhone) %></td>
<td><%: Html.ValidationMessageFor(m => m.ContactPhone, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Latitude) %></td>
<td><%: Html.TextBoxFor(m => m.Latitude) %></td>
<td><%: Html.ValidationMessageFor(m => m.Latitude, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Longitude) %></td>
<td><%: Html.TextBoxFor(m => m.Longitude) %></td>
<td><%: Html.ValidationMessageFor(m => m.Longitude, "*") %></td>
</tr>
<tr>
<td><input type ="submit" value="Save" /></td>
</tr>
</table>
</fieldset>
<% } %>
Remove the <% } %> from the bottom of your DinnerForm.ascx.
You've got an unpaired <% } %> at the end of your ascx file.
The form is missing. Looks like you omitted:
<% using( Html.BeginForm() ) { %>
from the top, just before the validation summary.
Related
Is there a way to put the following code in a gridview so I can do paging without updating the entire page.
<ASP:PANEL id="ResultsPanel" border="1" HorizontalAlign="Center" runat="server" Width="100%">
<ASP:REPEATER id="SearchResultsRepeater" runat="server" EnableViewState="False">
<HEADERTEMPLATE>
<TABLE BORDER="1" Style="width:800px"" Align="center" >
<TR>
<TD Class="StdSectionHeader2" Style="color: #FFFFFF;" Colspan="8">Select a Provider Name</TD>
</TR>
<TR>
<TH ID="header1" Class="StdTablePadding5 BlueTD" >Name</TH>
<TH ID="header2" Class="StdTablePadding5 BlueTD">Service Area</TH>
<TH ID="header4" Class="StdTablePadding5 BlueTD">Gender</TH>
<TH ID="header5" Class="StdTablePadding5 BlueTD">City</TH>
<TH ID="header6" Class="StdTablePadding5 BlueTD">Zip Code</TH>
<TH ID="header7" Class="StdTablePadding5 BlueTD">Processing<BR />Status</TH>
<TH ID="header8" Class="StdTablePadding5 BlueTD">Phone</TH>
</TR>
</HEADERTEMPLATE>
<ITEMTEMPLATE>
<TD Class="StdTablePadding5"><a class="three" href="default.asp" target="_blank">
<%# getStartLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString() )%>
<%# getNextPage(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString(),HCQA.ReferralRegistry.UI.Validation.EncodeDigits(((HCQA.ReferralRegistry.UI.User)Session["User"]).EncryptionKey,DataBinder.Eval(Container.DataItem, "IndividualID").ToString()))%>
<%# getMidLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%>
<%# DataBinder.Eval(Container.DataItem, "IndividualName").ToString()%>
<%# getEndLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%></a>
</TD>
<TD HEADERS="header2" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ServiceAreaName") %></TD>
<TD HEADERS="header4" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "gender") %></TD>
<TD HEADERS="header5" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "city") %></TD>
<TD HEADERS="header6" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ZipCode") %></TD>
<TD HEADERS="header7" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ProcessingStatus") %></TD>
<TD HEADERS="header8" Class="StdTablePadding5"><%# Util.FormatPhoneNumber(DataBinder.Eval(Container.DataItem, "PhoneNumber").ToString().Trim())%></TD>
</TR>
</ITEMTEMPLATE>
<ALTERNATINGITEMTEMPLATE>
<TR CLASS="AlternatingItemTemplate">
<TD HEADERS="header1" Class="StdTablePadding5">
<%# getStartLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString() )%>
<%# getNextPage(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString(),HCQA.ReferralRegistry.UI.Validation.EncodeDigits(((HCQA.ReferralRegistry.UI.User)Session["User"]).EncryptionKey,DataBinder.Eval(Container.DataItem, "IndividualID").ToString()))%>
<%# getMidLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%>
<%# DataBinder.Eval(Container.DataItem, "IndividualName").ToString()%>
<%# getEndLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%>
</TD>
<TD HEADERS="header2" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ServiceAreaName") %></TD>
<TD HEADERS="header4" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "gender") %></TD>
<TD HEADERS="header5" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "city") %></TD>
<TD HEADERS="header6" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ZipCode") %></TD>
<TD HEADERS="header7" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ProcessingStatus") %></TD>
<TD HEADERS="header8" Class="StdTablePadding5"><%# Util.FormatPhoneNumber(DataBinder.Eval(Container.DataItem, "PhoneNumber").ToString().Trim())%></TD>
</TR>
</ALTERNATINGITEMTEMPLATE>
<FOOTERTEMPLATE>
</table>
</FOOTERTEMPLATE>
</ASP:REPEATER>
I'm currently trying to paginate a list of records, however; after the last table, the page break leaves an empty page. The set up is an Aspx files that incorporates two ascx files to draw the table records.
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Table.ascx.cs" Inherits="%>
<br class="clear" /><br/>
<table class="report-table" cellspacing="0" cellpadding="2">
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("PatientBills") %>' OnItemDataBound="Repeater1_OnItemDataBound">
<HeaderTemplate>
<tr>
<td>Seq</td>
<td>Billing Id</td>
<td>Patient Id</td>
<td>Patient Name</td>
<td>Sex</td>
<td class="PrintNormalWrap">Admit Date</td>
<td class="PrintNormalWrap" style="width: 80px;">Social Security</td>
<td>DOB</td>
<td>POS</td>
<td>CPT</td>
<td>Mods</td>
<td style="width: 220px;">Diagnosis</td>
<td class="PrintNormalWrap">Referring Provider(UPIN)/ Comment</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="billRowShade<%# Container.ItemIndex % 2 %>">
<asp:TableCell ID="tableCellSequence" runat="server"><%# Container.ItemIndex + 1 %></asp:TableCell>
<td><%# FormatBillingId(Eval("Bill.BillingId")) %></td>
<td><%# FormatField(Eval("Patient.PatientId")) %></td>
<td id="printPatientName"><%# FormatField(Eval("Patient.LastName")) %>, <%# FormatField(Eval("Patient.FirstName")) %></td>
<td><%# FormatField(Eval("Patient.Sex")) %></td>
<td><%# FormatShortDate(Eval("Patient.DateOfAdmittance"))%></td>
<td><%# FormatField(Eval("Patient.SocialSecurityNumber")) %></td>
<td><%# FormatShortDate(Eval("Patient.DateOfBirth"))%></td>
<td><%# FormatField(Eval("Bill.Pos")) %></td>
<td><%# FormatField(Eval("Bill.CptCode")) %></td>
<td><%# FormatField(Eval("Bill.Mod")) %></td>
<td><%# FormatDiagnoses(Eval("Bill.Diagnoses"), Eval("Bill.BillDate"), Eval("Bill.SiteName")) %></td>
<td class="PrintNormalWrap"><%# FormatNotes(Eval("Patient.ReferringMd"), Eval("Patient.RefUpin"), Eval("Bill.Notes"), Eval("Bill.TimeEntry")) %> <%# FormatSupervisor( Eval("Bill.SupervisedByName"), Eval("Bill.DoctorName") ) %></td>
</tr>
<asp:TableRow ID="tableRowSpecialtyFieldDetails" runat="server" CssClass="specialtyFieldDetails">
<asp:TableCell ID="TableCell1" colspan="12" runat="server"><span id="spanSpecialtyFieldDetails" runat="server"></span></asp:TableCell>
</asp:TableRow>
</ItemTemplate>
</asp:Repeater>
</table>
<p style="page-break-after:always"></p>
<br/>
I have this table
<table id="Products" class="Products">
<tr>
<th>ProductId</th>
<th>Productname</th>
<th>Quantity</th>
<th>UnitPrice</th>
</tr>
<% for(int i=0; i < Model.NorthOrderDetails.Count; i++)
{
%>
<tr>
<td><%: Html.Label(Model.NorthOrderDetails[i].ProductID.ToString()) %></td>
<td><%: Html.Label(Model.NorthOrderDetails[i].ProductName) %> </td>
<td><%: Html.TextBoxFor(m => m.NorthOrderDetails[i].Quantity) %></td>
<td><%: Html.TextBoxFor(m => m.NorthOrderDetails[i].UnitPrice) %></td>
<td> <input type="submit" value="?" Name="qodel" /> </td>
</tr>
<% } %>
</table>
<% } %>
And I want to sent to controller the value of ProductID in line which I press button. How I can do it?
So without Javascript you are limiting yourself slightly here, I think the code below should work but I'm sure someone can poke a hole in it!
<table id="Products" class="Products">
<thead>
<tr>
<th>ProductId</th>
<th>Productname</th>
<th>Quantity</th>
<th>UnitPrice</th>
</tr>
</thead>
<tbody>
#{
for(int i=0; i < Model.NorthOrderDetails.Count; i++)
{
<tr>
<td>
#Html.Label(Model.NorthOrderDetails[i].ProductID.ToString())
</td>
<td>
#Html.Label(Model.NorthOrderDetails[i].ProductName)
</td>
<td>
#Html.TextBoxFor(m => m.NorthOrderDetails[i].Quantity)
</td>
<td>
#Html.TextBoxFor(m => m.NorthOrderDetails[i].UnitPrice)
</td>
<td>
#Html.ActionLink("Edit", "Vi")
</td>
<td>
<input type="submit" name="submitValue"
value="#Model.NorthOrderDetails[i].SomeValue"/>
</td>
</tr>
}
}
</tbody>
</table>
Then make sure that your controller action accepts the name attribute of the input as a parameter:
public ActionResult YourControllerMethod(string submitValue) {
....
}
The code would look something like that in MVC3+, <% is from MVC2.
I have aspx page. I dislay data in table. How I can get new values from this table in Controller. Or how I can generate grid/table another method in aspx page in mvc?
<table id="Products" class="Products">
<tr>
<th>ProductId</th>
<th>Productname</th>
<th>Quantity</th>
<th>UnitPrice</th>
</tr>
<% foreach (var item in Model.NorthOrderDetails)
{
%>
<tr>
<td><%: item.ProductID %></td>
<td><%: item.ProductName %></td>
<td><%: Html.TextBox("Quantity",item.Quantity) %></td>
<td><%: Html.TextBox("UnitPrice",item.UnitPrice) %></td>
<td> <%: Html.ActionLink("Update", "View2") %></td>
</tr>
<% } %>
</table>
The table should be wrapped in a form. Each text box should have a unique 'id' attribute. This can be done with a few simple changes to your code.
Something like this:
<form>
<table id="Products" class="Products">
<tr>
<th>ProductId</th>
<th>Productname</th>
<th>Quantity</th>
<th>UnitPrice</th>
</tr>
<% foreach (var item in Model.NorthOrderDetails)
{
%>
<tr>
<td><%: item.ProductID %></td>
<td><%: item.ProductName %></td>
<td><%: Html.TextBoxFor(m => item.Quantity) %></td>
<td><%: Html.TextBoxFor(m => item.UnitPrice) %></td>
</tr>
<% } %>
</table>
<button type="submit">Update</button>
</form>
Let us know if this helps!
I have the following code which is supposed to take some information from a C# page and display it inside the aspx page, but when I run it i provides me with the error:
"Expected class, delegate, enum, interface, or struct" at line 58 which is this one:
<asp:Repeater runat="server" ID="InboxRecords">
Can you please help me and tell me what could cause this problem?
<asp:Repeater runat="server" ID="InboxRecords">
<ItemTemplate>
<% if (inbox == true)
{%>
<tr>
<td><%#DataBinder.Eval(Container.DataItem, "Sending")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BA")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "Date")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "Title")%></td>
<td><%# if (test != Convert.ToString(DataBinder.Eval(Container.DataItem, "DocPath")))
{%>
Document
<%}
%>
</td>
<td><%#DataBinder.Eval(Container.DataItem, "Subject").ToString().Replace("\n","<br />") %></td>
<% if (_userTypeId == 1)
{%>
<td><a href="Notifications.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "Id")%>&delete=1"><img src="img\delete.png" alt="Delete" title="Delete" /></td>
<%}
%>
<%}
%>
</tr>
</ItemTemplate>
</asp:Repeater>