div に期待どおりのコンテンツが表示されない
私のコントローラーアクション:
/// <summary>
/// GetCountiresForManufacturer
/// </summary>
/// <returns></returns>
[Authorize(Roles = "Administrator")]
[AcceptVerbs(HttpVerbs.Get)]
public string GetCountiresForManufacturer(string manufacturer)
{
var sb = new StringBuilder();
var rows = new List<Manufacturer>();
var data = new Dictionary<string, List<Country>>();
// var countries = new List<Country>();
if (manufacturer.StartsWith(","))
{
manufacturer = manufacturer.TrimStart(',');
}
string[] manufacturers = manufacturer.Split(',');
foreach (var s in manufacturers)
{
var manufacturerRow = _manufacturerRepository.GetManufacturerByName(s);
rows.Add(manufacturerRow);
}
foreach (var row in rows)
{
if(row==null)
{
continue;
}
var countriesList = _countryRepository
.GetAllCountriesForManufacturer(row.Id);
// countries.Add(countriesList);
data.Add(row.Description, countriesList.ToList());
}
foreach (var s in data)
{
sb.Append(" <input id =\"Brand\" name=\"Brand\" value=\""+s.Key+"\"/>");
foreach (var manufacturer1 in s.Value)
{
sb.Append("<input id =\"Dove\" type=\"checkbox\"
value=\""+manufacturer1.Name+"\"/>");
}
}
return sb.ToString();
}
私の見解:
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<EmsAdmin.Models.User>" %>
<%@ Import Namespace="EmsAdmin.Models" %>
<%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and
try again.") %>
<% using (Html.BeginForm(new {}))
{%>
<%= Html.AntiForgeryToken() %>
<%: Model.Id %>
<%= Html.HiddenFor(e=>e.SelectedBrands) %>
<p>
<%= Html.LabelFor(e=>e.Name,"Name:") %>
<%= Html.TextBoxFor(e => e.Name, new { @style = "width: 255px;" })%>
<%= Html.ValidationMessageFor(e=>e.Name,"") %>
</p>
<p>
<%= Html.LabelFor(e=>e.Email,"Email:") %>
<%= Html.TextBoxFor(e => e.Email, new { @style = "width:250px;" })%>
<%= Html.ValidationMessageFor(e=>e.Email,"") %>
</p>
<p>
<%= Html.LabelFor(e=>e.Corporation.Description,"Corporation:") %>
<%= Html.TextBoxFor(e => e.Corporation.Description, new { @style = "width:250px;" })%>
<%= Html.ValidationMessageFor(e=>e.Corporation.Description,"") %>
</p>
<hr />
<h2>Approve User</h2>
<p>
<%= Html.LabelFor(e=>e.Approve,"Aprrove User:") %>
<%= Html.CheckBoxFor(e=> e.Approve,Model.Approve) %><span> Switch this on if you
want to
add regitrar </span>
<%= Html.ValidationMessageFor(e=>e.Approve,"") %>
</p>
<hr />
<h2>Multi Select Brands If Required:</h2>
<div id="checkboxes">
<% foreach (var manufacturer in Model.Manufacturer)
{%>
<input type="checkbox" id="<%: manufacturer.Id %>" class="checkbox" value="<%:
manufacturer.Description %>" /><%: manufacturer.Description %><br />
<%} %>
<input type="submit" value="UpdateBrands" class="brands" />
</div>
<div id="checkboxescountries" class="divNewCountriesList">
</div>
<hr />
<p>
<input type="submit" value="Save" />
<%= Html.ActionLink("Cancel","Details",new {id=Model.Id},new {@title="exit without
saving"}) %>
</p>
<% } %>
<script type="text/javascript">
$(".brands").click(function(event) {
event.preventDefault();
var selected = "";
var manu = "";
var input = "";
$("#checkboxes input:checked").each(function() {
manu = $(this).val();
selected = selected + "," + manu;
alert(selected);
$("#SelectedBrands").val(selected);
alert($("#SelectedBrands").val());
});
var productInput = "";
alert("I am here");
var myUrl = "/Countries/GetCountiresForManufacturer/" + selected;
alert(myUrl);
$.ajax({
url: myUrl,
type: 'get',
success: function(data) {
productInput = data;
alert(productInput);
//$('.brands').after("<div id='divNewCountriesList" + id + "' class ='divNewCountriesList'"+" </div>");
}
});
$(".divNewCountriesList").html(productInput);
});
注:私が与える場合
$(".divNewCountriesList").html("Hello World");
div には表示されますが、productInput には表示されません。どこが間違っているのかわかりません。