I'm having a bit of an issue with an Ajax form. I've probably done it a bit backwards no doubt. Basically, when I hit the submit button in the form, nothing at all happens. I've debugged however it doesn't appear to post to the action method. It literally does nothing.
Here is my code so far:
Basically I post information from a form with the model of DetailedBreakdownReportRequest. This model is being passed through fine as my page displays the list of initial unfiltered results.
DetailedBreakdownReport Action Method:
[HttpPost]
public ActionResult DetailedBreakdownReport(DetailedBreakdownReportRequest reportRequest, FormCollection formVariables)
{
return View(reportRequest);
}
DetailedBreakdownReport View
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<MyApp.Data.AdvancedReports.AdvancedReports.DetailedBreakdownReports.DetailedBreakdownReportRequest>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Detailed Breakdown Report
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script language="javascript" type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.4.1.min.js")%>"></script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<% using (Ajax.BeginForm("DetailedList", "Reports",
new AjaxOptions
{
UpdateTargetId = "panelBreakdownList",
InsertionMode = InsertionMode.Replace
},
new { id = "SearchForm" })) %>
<% { %>
<div style="position: absolute; top: 0px; height: 30px; right: -12px; margin-top: 8px;
width: 250px; padding-left: 00px; vertical-align: middle; display: inline-block;">
<input id="searchField" name="searchField" style="padding-left: 5px; position: relative;
float: left; top: 3px; margin: 0px; border: 1px solid #DDDDDD; height: 19px;
width: 200px;" />
<%: Html.HiddenFor(m => m.ToDate) %>
<%: Html.HiddenFor(m => m.FromDate) %>
<%: Html.HiddenFor(m => m.Currency) %>
<%: Html.HiddenFor(m => m.ReportType) %>
<!--<input type="image" src="/Content/Images/search-form-submit.png" style="border: 0px;
height: 27px; position: relative; left: -8px; margin: 0x; float: left;" />-->
<input type="submit" value="Search" style="border: 0px;
height: 27px; position: relative; left: -8px; margin: 0x; float: left;" />
</div>
<% } %>
<div id="panelBreakdownList" style="position: relative; z-index: 0;">
<% Html.RenderAction("DetailedList", new { ToDate = Model.ToDate, FromDate = Model.FromDate, Currency = Model.Currency, ReportType = Model.ReportType }); %>
</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Header" runat="server">
<h1>Detailed Breakdown Report</h1>
<h2><%: Model.ToDate.ToString("dd-MMM-yyyy") %> to <%: Model.FromDate.ToString("dd-MMM-yyyy")%></h2>
</asp:Content>
Here is the DetailedList action that is called from the above page, and it's view:
[HttpPost]
public ActionResult DetailedList(DateTime ToDate, DateTime FromDate, string Currency, string ReportType, FormCollection formVariables)
{
DetailedBreakdownReportRequest reportRequest = new DetailedBreakdownReportRequest()
{
ToDate = ToDate,
FromDate = FromDate,
Currency = Currency,
ReportType = ReportType,
UserId = UserServices.CurrentUserId
};
DrilldownReportEngine re = new DrilldownReportEngine();
DetailedBreakdownReport report = null;
if (formVariables.HasKeys())
{
reportRequest.searchTerm = formVariables["searchField"];
report = re.GetDetailedBreakdown(reportRequest);
}
else
{
report = re.GetDetailedBreakdown(reportRequest);
}
return PartialView(report);
}
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Data.AdvancedReports.AdvancedReports.DetailedBreakdownReports.DetailedBreakdownReport>" %>
<% if (Model.HasData)
{ %>
<% if (Model.ShopBreakdown != null)
{ %>
<h2>Shop Breakdown Report</h2>
<p>Click on a shop's name to see additional information.</p>
<div id="shopGrid" style="float:left; width: 400px;">
<table width="400px">
<% foreach (var shop in Model.ShopBreakdown)
{ %>
<tr>
<td colspan="3"><h2><%: Html.ActionLink(shop.Shop.Name + " >>", "ShopDashboard", new { ShopId = shop.Shop.ShopID, Currency = Model.Currency, toDate = Model.ToDate.ToString(), fromDate = Model.FromDate.ToString(), percentageOfSales = shop.RevenuePercentageOfSales })%></h2></td>
</tr>
<tr>
<td><p class="labels">Units Sold:</p></td>
<td><b style="font-size:larger;"><%: shop.UnitsSoldPerShop%></b></td>
<td rowspan="2" align="center"><h2><%: String.Format("{0:0.0%}", shop.RevenuePercentageOfSales)%></h2> of Total Revenue</td>
</tr>
<tr>
<td><p class="labels">Revenue Earned:</p></td>
<td><b style="font-size:larger;"><%: String.Format("{0:0.00}", shop.TotalRevenuePerShop)%></b></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<% } %>
</table>
</div>
<% } %>
<% if (Model.ProductBreakdown != null)
{ %>
<% foreach (var product in Model.ProductBreakdown)
{ %>
<div id="ProductGrid" style="float:left; width: 500px;">
<div>
<h3><%: Html.ActionLink(product.Product.Name + " >>", "ProductDashboard", new { ProductId = product.Product.ProductID, Currency = Model.Currency, toDate = Model.ToDate.ToString(), fromDate = Model.FromDate.ToString(), percentageOfSales = product.RevenuePercentageOfSales })%></h3>
</div>
<div style="float:left; width: 200px;">
<p class="labels">Units Sold: </p><b style="font-size:larger;"><%: product.TotalUnitsSoldPerProduct %></b>
<br />
<p class="labels">Revenue Earned: </p><b style="font-size:larger;"><%: String.Format("{0:0.00}", product.OverallTotalRevenuePerProduct)%></b>
</div>
<div style="float: left; text-align: center;">
<h2><%: String.Format("{0:0.0%}", product.RevenuePercentageOfSales)%></h2> of Total Revenue
</div>
</div>
<% } %>
<div style="clear:both;" />
<br />
<% } %>
<% } %>
As I said above, on first load, the page displays fine, it displays an unfiltered view of the results. When I type in a value into the text box and click submit, nothing at all happens and I'm finding that hard to debug. At least if it did something I'd have something to work with. Can anyone see if I'm doing something wrong here?
As I see, you expect some not nullable variables in action detailedList which are expected from form.
[HttpPost]
public ActionResult DetailedList(DateTime ToDate, DateTime FromDate, string Currency, string ReportType, FormCollection formVariables)
{
......
}
But you just send searchfield in form collection. Where is the ToDate, FromDate, Currency variables in form?
I think you should create a formmodel forexample
DetailedListSearchModel
DateTime ToDate
DateTime FromDate
string Currency
string ReportType
string Searchfield
and make search a partialview. Just pass default values when partial view is rendered with default values then execute in form.
Then you will take this values in action like
[HttpPost]
public ActionResult DetailedList(DetailedListSearchModel model)
{
......
}
You can use this model in form like
<%= Html.LabelFor(m => m.Searchfield) %>
<%= Html.TextBoxFor(m => m.Searchfield, new { #class = "css classes", maxlength = "1000" })%>
<%= Html.ValidationMessageFor(m => m.Searchfield) %>
$(function() {
$('form#SearchForm').find('a.submit-link').click( function() {
$('form#SearchForm').trigger('submit');
}).show();
}
and change search button to a.
Search
Related
I have a grid table which I'm trying to click one of its column's without any success so far.
I can get its content\data(of each of the coulmns) , but when clicking on it, the test passes but does not really click on the requested element. either not on the row nor the column.
I tried it in two different ways:
WebDriverWait wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(10));
_webdriver.SwitchTo().Frame("WebResource_kendoHistory");
var tbl = _webdriver.FindElements(By.Id("tblMain"));
var gridmaster = tbl[0].FindElement(By.Id("tdGridMaster"));
var gridcontent = gridmaster.FindElement(By.CssSelector("div.k-grid-content"));
var tableselectable = gridcontent
.FindElement(By.CssSelector("table.k-selectable"));
var tr = tableselectable.FindElements(By.CssSelector("tr[role='row']"));
var td = tr[1].FindElements(By.TagName("td"));
td[1].Click();
And by this as well:
var element = wait.Until(
ExpectedConditions.ElementToBeClickable(
By.CssSelector(".k-selectable tr[role='row']")
)
);
element.Click();
I have tried to make a Javascript click as well without any success.
This is part of the Html:
<!DOCTYPE html>
<html class="k-ie k-ie11">
<head>
<title></title>
</head>
<body class="k-rtl" style="width: 100%; height: 100%;">
<div class="k-widget k-splitter" id="splitterDiv" data-role="splitter">
<div class="k-pane k-scrollable" id="incidentsDiv" role="group" >
<table id="tblMain" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td id="tdGridMaster" colspan="5">
<div class="k-grid k-widget"
id="gridMaster" data-role="grid"
style="width: 100%; height: 242px;" >
<div class="k-grid-content" style="height: 163px;">
<table class="k-selectable" role="grid"
data-role="selectable">
<tbody role="rowgroup">
<tr role="row"
data-uid="c65559ae-8b2f-4768-9cb9-7a9f7c3dc3ba">
<td>
<a style="color: blue; text-decoration: underline; cursor: pointer;"
onclick="motherOrBatClicked('null',' ')"> </a>
</td>
<td>2018-4315</td>
<td>incident</td>
<td>חss</td>
<td>2018-8888</td>
<td style="display: none;"> </td>
<td><sssa1></td>
<td>Joe</td>
<td>12/04/2018</td>
<td> </td>
<td>Digitar</td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
var tbl = _webdriver.FindElement(By.CssSelector("#tblMain #gridMaster table.k-selectable"));
var firstCell = tbl.FindElement(By.CssSelector("tr[role='row'] > td"));
var firstLink = firstCell.FindElement(By.CssSelector('a'));
WebDriverWait wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementToBeClickable(firstLink));
firstLink.click();
Can someone help me please?
I would like to pass the input values of the two textboxes to the controller of the view.
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/personenbeheer.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<UDL.Domain.Persoon>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PersonenbeheerContent" runat="server">
<legend class="form-signin-heading">Personenlijst</legend>
<% Html.BeginForm("Index", "Persoon", FormMethod.Get);%>
<% var currentUser = HttpContext.Current.User; %>
<% if (currentUser.IsInRole("Beheerder"))
{ %>
<nav>
<ul class="nav nav-pills nav-justified" role="tablist">
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;"><%: Html.ActionLink("Maak persoon aan", "Create", null, new { #class="UDLbutton" })%></li>
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;"><%: Html.ActionLink("Lijst Pdf", "PrintPersonen", new { sort = ViewData["sort"], zoeknaam = ViewData["zoekNaam"]}, new { target = "_blank",#class="UDLbutton"}) %></li>
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;">
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#etiketten"> Adres etiketten</button></li>
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;"><%: Html.ActionLink("Export emailadressen","ExportEmails", new { sort = "Adres", zoeknaam = ViewData["zoekNaam"]}, new { target = "_blank",#class="UDLbutton"}) %></li>
</ul>
</nav>
<% } %>
<% Html.BeginForm("Index", "Persoon", FormMethod.Post);
{ %>
<input type="text" id="txtA"/>
<input type="text" id="txtB"/>
<input type="submit" value="Verzenden"/>
<% } %>
As you can see I use twice Html.BeginForm for the same method but once for a GET and once for a POST. But the POST isn't working :(
This is the controller:
//
// GET: /Persoon/
[Authorize(Roles = "Gebruiker, Beheerder")]
public ActionResult Index(string sortOrder, string zoekNaam, int? page, string huidigefilter)
{
//huidige zoekfilter
ViewBag.huidigzoeken = sortOrder;
//ViewBags om waarden door te geven naar de View en ze geven data over het sorteren door
ViewBag.PersoonIDSortParm = String.IsNullOrEmpty(sortOrder) ? "PersoonID_desc" : "";
ViewBag.NaamSortParm = sortOrder == "Naam" ? "Naam_desc" : "Naam";
ViewBag.AanhefSortParm = sortOrder == "Aanhef" ? "Aanhef_desc" : "Aanhef";
ViewBag.GemeenteSortParm = sortOrder == "Gemeente" ? "Gemeente_desc" : "Gemeente";
ViewBag.GeslachtSortParm = sortOrder == "Geslacht" ? "Geslacht_desc" : "Geslacht";
ViewBag.AdresSortParm = sortOrder == "Adres" ? "Adres_desc" : "Adres";
ViewBag.VoornaamSortParm = sortOrder == "Voornaam" ? "Voornaam_desc" : "Voornaam";
ViewBag.TelefoonSortParm = sortOrder == "Telefoon" ? "Telefoon_desc" : "Telefoon";
ViewBag.GSMSortParm = sortOrder == "GSM" ? "GSM_desc" : "GSM";
ViewBag.EmailSortParm = sortOrder == "Email" ? "Email_desc" : "Email";
ViewBag.PartnerSortParm = sortOrder == "Partner" ? "Partner_desc" : "Partner";
ViewBag.OpmerkingenSortParm = sortOrder == "Opmerkingen" ? "Opmerkingen_desc" : "Opmerkingen";
//ViewBag.StatusLidSortParm = sortOrder == "StatusLid" ? "StatusLid_desc" : "StatusLid";
ViewBag.huidigefilter = zoekNaam;
ViewData["sort"] = sortOrder;
ViewData["zoekNaam"] = zoekNaam;
//Enkel de personen tonen die geen lid zijn
var personen = PersoonBLL.SorteerZoeken(sortOrder, zoekNaam, page, huidigefilter);
ViewData["PersonenCount"] = PersoonBLL.SorteerZoekenNotPaged(sortOrder, zoekNaam).ToList().Count;
return View(personen);
}
[HttpPost]
public ActionResult Index(String a, String b)
{
return View("Index");
}
I use a breakpoint for the HttpPost method but it's never going in.
You need to set the name attribute of each input element to match the parameter name in the controller method.
So you should have in your view:
<input type="text" id="txtA" name="txtA" />
<input type="text" id="txtB" name="txtB" />
And in your controller:
public ActionResult Index(String txtA, String txtB)
When you want two forms inside your page you have to end the form by doing:
<%Html.EndForm(); %>
So now my code looks like this:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/personenbeheer.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<UDL.Domain.Persoon>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PersonenbeheerContent" runat="server">
<legend class="form-signin-heading">Personenlijst</legend>
<% Html.BeginForm("Index", "Persoon", FormMethod.Get);%>
<% var currentUser = HttpContext.Current.User; %>
<% if (currentUser.IsInRole("Beheerder"))
{ %>
<nav>
<ul class="nav nav-pills nav-justified" role="tablist">
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;"><%: Html.ActionLink("Maak persoon aan", "Create", null, new { #class="UDLbutton" })%></li>
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;"><%: Html.ActionLink("Lijst Pdf", "PrintPersonen", new { sort = ViewData["sort"], zoeknaam = ViewData["zoekNaam"]}, new { target = "_blank",#class="UDLbutton"}) %></li>
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;">
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#etiketten"> Adres etiketten</button></li>
<li role="presentation" class="alert-info" style="border: 2px solid white; border-radius: 5px;"><%: Html.ActionLink("Export emailadressen","ExportEmails", new { sort = "Adres", zoeknaam = ViewData["zoekNaam"]}, new { target = "_blank",#class="UDLbutton"}) %></li>
</ul>
</nav>
<% } %>
<%Html.EndForm(); %>
<% Html.BeginForm("Index", "Persoon", FormMethod.Post);
{ %>
<input type="text" id="txtA" name="txtA"/>
<input type="text" id="txtB" name="txtB"/>
<input type="submit" value="Verzenden"/>
<% } %>
<%Html.EndForm(); %>
We have an issue, when the session timeout occurs - it logsoff the user and then presents the login screen. The issue is we have a page header which has tabs for user to hit. But we also present most common tab grid automatically. The page header stays. So after the timeout, that page header is there and new page header displays so there are 2 of them.
way out is to x out and relogin. But there must be some way to clear the entire page when there is timeout, this is my header page
<
%# Page Language="C#" AutoEventWireup="true" CodeBehind="Interchange.aspx.cs" Inherits="FDB.Views.Interchange" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script lang="jv" type="text/javascript">
function SetHiddenValue(fieldName, val) {
if (hfCommon.Contains(fieldName))
hfCommon.Set(fieldName, val);
else
hfCommon.Add(fieldName, val);
}
function GetHiddenValue(fieldName) {
if (hfCommon.Contains(fieldName))
return hfCommon.Get(fieldName);
else
return null;
}
function ImageClick(s, e) {
var val = GetHiddenValue('ShowHideFilter');
if (val == null)
SetHiddenValue('ShowHideFilter', true);
else {
SetHiddenValue('ShowHideFilter', !val);
}
val = GetHiddenValue('ShowHideFilter')
gvPBMCharges.PerformCallback('ShowHideFilter,' + val.toString());
}
function TreeCheckedChanged(s, e) {
gvPBMCharges.PerformCallback(e.node.name + '');
}
function ColExpClickFacility() {
//debugger;
var divM = document.getElementById('ASPxRoundPanel1_div3');
if (divM != undefined && divM != null) {
if (divM.style.display == 'block') {
divM.style.display = 'none';
hlColExpFacility.SetText('Expand Facility');
}
else {
divM.style.display = 'block';
hlColExpFacility.SetText('Collapse Facility');
}
}
}
function ColExpClick() {
var divM = document.getElementById('div1');
var divTop = document.getElementById('divTop');
if (divM != undefined && divM != null) {
if (divM.style.display == 'block') {
divM.style.display = 'none';
//s.SetImageUrl('../Content/Images/expand.png');
hlColExp.SetText('Expand Instructions');
divTop.style.height = '45px';
}
else {
divM.style.display = 'block';
//s.SetImageUrl('../Content/Images/collapse.png');
hlColExp.SetText('Collapse Instructions');
divTop.style.height = '165px';
}
}
}
function CheckedChangedSelectAll(s, e) {
if (s.GetChecked()) {
cblFacility.SelectAll();
}
else {
cblFacility.UnselectAll();
}
gvPBMCharges.PerformCallback('');
}
function SelectedIndexChangedFacility(s, e) {
gvPBMCharges.PerformCallback('');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div runat="server" id="divTop">
<div runat="server" id="divTitle" style="float: left; width: 50%;">
</div>
<div runat="server" id="divFilter" style="float: right; text-align: right; width: 49.84%; height: 34px; padding-top: 10px;">
<table border="0" style="width: 100%;">
<tr>
<td style="padding-left: 3px; padding-top: 3px; text-align: right;">
<div runat="server" id="div2" style="width: 100%; padding-bottom: 5px;">
<dx:ASPxHyperLink runat="server" ID="hlColExp" Font-Underline="true" ClientInstanceName="hlColExp" Text="Expand Instructions" NavigateUrl="javascript:ColExpClick();">
</dx:ASPxHyperLink>
</div>
</td>
<td style="padding-left: 3px; text-align: right; width: 90px;">Select Patient:
</td>
<td style="padding-left: 3px; text-align: right; width: 215px;">
<dx:ASPxComboBox runat="server" ID="cboPatient" ValueField="Id" TextField="Name" NullText="Select patient from drop down" Width="200">
<ClientSideEvents SelectedIndexChanged="function(s,e){ gvPBMCharges.PerformCallback(''); }" />
</dx:ASPxComboBox>
</td>
</tr>
</table>
</div>
I have the following form elements in a Spanish language website (ASP.Net MVC3)
(truncated, of course)
<label for="RazonSocial">Razón Social</label>
<input type="text" id="RazonSocial" name="RazonSocial" class="span12" value=""/>
<label class="radio" for="razon_social_emp">Empresa
<input type="radio" name="Razon_Social" id="razon_social_emp" value="Empresa" />
</label>
<label class="radio" for="razon_social_pf">Persona Física
<input type="radio" name="Razon_Social" id="razon_social_pf" value="Persona Física" />
</label>
Now, I'm sending those values in an HTML email using this model:
(truncated, of course)
public class RegistrationEmailModel
{
public string RazonSocial { get; set; }
public string Razon_Social { get; set; }
}
This is the email view:
(truncated, of course)
#model MyNamespace.Models.RegistrationEmailModel
<html>
<head>
<style type="text/css">
body { font-family:"Lucida Grande",verdana,arial,helvetica,sans-serif; font-size:11px;}
.h3 {color:#CC6600; font-weight: bold; font-size: 14px;}
.header { margin-top: 10px; margin-bottom: 5px; text-align: left; border-bottom: 1px solid #C6600; }
.p10 { font-size 11px; margin-top: 3px; margin-bottom: 3px;}
.rt {text-align: right; width: 25%; }
</style>
</head>
<body>
<table width="660px" border="0" cellpadding="0" cellspacing="0" class="style1">
<tr>
<td class="rt">
<span class="p10">Razón Social: </span>
</td>
<td>
<span class="p10"><b>#Model.RazonSocial</b></span>
</td>
</tr>
<tr>
<td class="rt">
<span class="p10">Tipo de Razón Social: </span>
</td>
<td>
<span class="p10"><b>#RazonSocial</b></span>
</td>
</tr>
</table>
</body>
</html>
The issue I'm having is that the value of the Razon_Social radio button does not come over in the email with the accented char.
How can I convert that to properly send the accented char in the email?
Edit:
Here's the RenderPartialViewToString() function:
public static string RenderPartialViewToString(Controller controller, string viewName, object model)
{
controller.ViewData.Model = model;
try
{
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
Try adding the utf-8 meta header to your email template.
If you are using HTML5:
<meta charset="utf-8">
or if you are using HTML 4:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
By the way specify what you are using with a proper DOCTYPE field. For example for HTML5 that would be:
<!DOCTYPE html>
Oh and by the way, a bit off topic, but radio buttons in an email? Really? What for?
I ended up using ActionMailer.Net (http://geeksharp.com/2011/01/26/actionmailer-net-email-templates-for-the-mvc-crowd/) and wrote an OnMailSending() handler to replace the offending character. I am not sure if any other characters will cause an issue but at least it works for now. I will keep monitoring.
OnMailSending() handler in my MailController:
protected override void OnMailSending(MailSendingContext context)
{
for (var i = 0; i < context.Mail.AlternateViews.Count; i++)
{
var av = context.Mail.AlternateViews[i];
if (av.ContentType.MediaType == MediaTypeNames.Text.Html)
{
av.ContentStream.Position = 0;
var content = new StreamReader(av.ContentStream).ReadToEnd();
content = content.Replace("F?sica", "Física");
context.Mail.AlternateViews[i] = AlternateView.CreateAlternateViewFromString(content, av.ContentType);
}
}
base.OnMailSending(context);
}
I dont understand what am i missing here? in my view my code lists each group twice??
<% foreach (var group in Model.AllGroups) //53 entries here
{ %>
<% foreach (var groupForUser in Model.GroupsForUser) //2 entries here
{ %>
<% if (group.GroupId == groupForUser.GroupId)
{ %>
<div id="Div1" style="width:auto; height:50px; border:solid 1px black; margin:5px; **background-color:green**;" >
<h3> <%: groupForUser.Name %></h3>
</div>
<input type="hidden" id="Hidden1" name="group<%: group.GroupId %>" value="" />
<% }
else %>
<% { %>
<div id="group-select<%: group.GroupId %>" style="width:auto; height:50px; border:solid 1px black; margin:5px;" >
<h3> <%: group.Name %></h3>
</div>
<input type="hidden" id="group<%: group.GroupId %>" name="group<%: group.GroupId %>" value="" />
<% } } }%>
is there a better way of doing this? and also why are the groups listed twice in my view?
thanks
They're listed twice because you have 2 entries within GroupsForUsers and you are outputting every group on each iteration (because of your else statement in the inner foreach).
A better way would be to cut out the inner loop completely (using Linq), something like:
<% foreach (var group in Model.AllGroups)
{ %>
<% if (Model.GroupsForUsers.Any(g => g.GroupId == group.GroupId)
{ %>
//make it green
<% }
else %>
<% { %>
//make it red
<% } }%>