I have a project were you select dates in a list, and than report x-amount of hours on a project on. It looks like this:
But what I want to is, I want to add a check-box after the months name if I want to select all dates under that month. But I am currently not sure how I would do that so I would be glad if I could get some guidance.
This is the view that prints out all the dates:
<form class="form-horizontal">
<div class="portlet-body form">
<div class="form-group">
#if (ViewBag.MissingDays != null)
{
int i = 0;
var months = ((List<DateTime>)ViewBag.MissingDays).GroupBy(x => x.Month);
IEnumerable<IGrouping<int, DateTime>> groups = months as IList<IGrouping<int, DateTime>> ?? months.ToList();
foreach (var group in groups)
{
i++;
var month = CultureInfo.CreateSpecificCulture("sv-SE").DateTimeFormat.GetMonthName(group.Key);
if (groups.Count() > 1)
{
<div class="panel-group accordion" id="accordion1">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapse_#i">
#month
</a>
</h4>
</div>
<div id="collapse_#i" class="panel-collapse collapse">
<div class="panel-body">
<div class="col-md-12">
#foreach (var date in group)
{
var isoDate = date.ToString("yyMMdd");
var day = date.ToString("ddd", new CultureInfo("sv-SE")).Substring(0, 2);
<label style="padding-left: 10px">
<input type="checkbox" id="isoDate" name="isoDate" value="#isoDate" />#day-#isoDate
</label>
}
</div>
</div>
</div>
</div>
</div>
}
else
{
<div class="col-md-12">
#foreach (var date in group)
{
var isoDate = date.ToString("yyMMdd");
var day = date.ToString("ddd", new CultureInfo("sv-SE")).Substring(0, 2);
<label style="padding-left: 10px">
<input type="checkbox" id="isoDate" name="isoDate" value="#isoDate" />#day-#isoDate
</label>
}
</div>
}
}
}
</div>
</div>
And this is the script on how I select the dates right now.
$(document).ready(function() {
$('input[name="isoDate"]').change(function() {
$("#date").val("");
$('input[name="isoDate"]').each(function() {
if (this.checked) {
$("#date").val($("#date").val() + " " + $(this).val());
}
});
});
});
You can try like this..
First remove the id="isoDate" as Id should be unique. And add a check box inside div near to month field
<input type="checkbox" class="selectAll" name="all" />
Now add a JQuery click handler
$(".selectAll").on("click", function() {
if ($(this).is(':checked')) {
$(this).closest('.panel-default').find("input[name='isoDate']").prop('checked',true);
} else {
$(this).closest('.panel-default').find("input[name='isoDate']").prop('checked',false);
}
});
See working FIDDLE
first time use diferent ids for each input element. Then use js or jquery. Some like this :
var i = 0;
var ids = "juli_150505_" + i;
i++;
then you finde any checkbox element whot you want. By JS or jQuery.
Or you can use class param, then GetElementByClass().
<input type="checkbox" id="isoDate" class="Juli" name="isoDate" value="#isoDate" />
Put a checkbox in front of every month name and give it a class name like 'chkAll'
$('input[name="chkAll"]').click(function(){ //if any chkAll is clicked
if (this.checked) {
$(this).find("input[type='checkbox']").each(function() {
//Loop through
$(this).prop('checked', true);
});
}
else
{
$(this).find("input[type='checkbox']").each(function() {
$(this).prop('checked', false);
});
}
});
Related
This question already has an answer here:
Get ID and Value from a checkbox: Return to model and use in method to insert into sql database
(1 answer)
Closed 1 year ago.
I'm trying to add values to a cross table, where the ID of a garage and a value based on a list of choices gets inserted to the database. The list looks like following in the view:
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<label class="ab">Claim</label>
<input type="checkbox" class="checkbclass" name="Claim" id="Claim" placeholder="Claim" required="" />
</div>
</div>
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<label class="ab">Scheduled Service</label>
<input type="checkbox" class="checkbclass" name="Scheduled" id="Scheduled" placeholder="Scheduled" required="" />
</div>
</div>
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<label class="ab">Tires</label>
<input type="checkbox" class="checkbclass" name="Tires" id="Tires" placeholder="Tires" required="" />
</div>
</div>
So 3 checkboxes is shown in the view. Here the user is supposed to choice one or more options when they edit a garage. The cross table looks like following:
[ID]
,[GarageID]
,[RequestProperty]
,[CreatedDate]
,[CreatedBy]
,[UpdatedDate]
,[UpdatedBy]
I would like to do something similar to this in SQL stored procedure:
INSERT INTO GarageCrossRequestType
(GarageID, RequestProperty)
VALUES (#GarageID, #RequestType)
Which could look something similar to:
var cmd1 = new SqlCommand("spGarageGetRequestTypes", Connection);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("#GarageId", model.GarageId);
cmd1.Parameters.AddWithValue("#RequestType", model.requestId);
int result = cmd1.ExecuteNonQuery();
if (result == 1)
valid = true;
In the method. (To insert the garageID and the RequestTypeID.)
The Request-types can be as following:
public int Claim { get; set; } = 1;
public int ScheduledService { get; set; } = 2;
public int Tires { get; set; } = 3;
So for example, if a user choose Claim, I would like to update the table with the GarageID and Claim -> which ID would be 1. I'm sort of new to working with views, so I'm not sure how I would connect the input types to the model. So the problems are as following:
Connect the input types to the model, giving them their correct value (ex. Claim -> 1, Scheduled -> 2 etcetera) and,
My database table only accept garageId and requestType, and therefore when sending for example garageId: 4, I would need the input type Claim or whatever checkbox is choosen to only send their value (1, 2 or 3) to the database.
Anyone got a solution for this? Also I hope this makes sense, let me know otherwise and i'll try to formulate it differently.
UPDATE:
So I should have explained better from the beginning. But here's the rest of the code. So basically, there's a function where a user can Edit a garage where I would like to make it possible for them to also choose either claim/service or tires. So I would like to expand this method, and when a user selects a garage this is when they also can choose claim etcetera (It's also from this method the garageId comes from).
In the view (for edit garage):
<div class="form-group">
<div class="row">
<label class="col-xs-2 control-label">Garage</label>
<input type="text" class="col-lg-10 form-control" name="GarageName" id="GarageName" placeholder="Name" required="" />
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-2 control-label">Contact person</label>
<input type="text" class="col-lg-10 form-control" name="ContactPerson" id="ContactPerson" placeholder="ContactPerson" required="" />
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-2 control-label">Email</label>
<input type="email" class="col-lg-10 form-control" name="Email" id="Email" placeholder="Email" required="" onblur="validateEmail(this.value);" /><p id="InvalidMeg" style="font-size: 25px; color: red">Invalid e-mail address</p>
</div>
</div>
<button class="btn btn-md btn-primary custom" type="submit" id="saveNewGarageBtn"><i class="glyphicon glyphicon-lock"></i> Save</button>
<button class="btn btn-md btn-primary custom" type="submit" id="EditGarageBtn"><i class="glyphicon glyphicon-lock"></i> Save edit</button>
Javascript:
function editGarage(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var garageId = dataItem.GarageId;
countryId = dataItem.CountryId;
name = dataItem.Name;
var contactperson = dataItem.ContactPerson;
var email = dataItem.Email;
if (garageId != 0) {
$("#EditGarageBtn").show();
$("#saveNewGarageBtn").hide();
$("#GarageName").val(name);
$("#Country").val(countryId);
$("#ContactPerson").val(contactperson);
$("#Email").val(email);
$("#garageId").val(garageId);
}
}
Edit-garage button:
$("#EditGarageBtn").click(function () {
var customerNumber = customerNumberOfEditingGarage;
name = $("#GarageName").val();
countryId = $("#Country").val();
var garageId = $("#garageId").val();
var contactperson = $("#ContactPerson").val();
var email = $("#Email").val();
$("#EditGarageBtn").hide();
if (countryId == "Norway")
countryId = 2;
if (countryId == "Finland")
countryId = 4;
if (name.length > 0 && email.length > 0 && phone.length > 0 && contactperson.length > 0) {
$.ajax({
url: '#Url.Action("EditGarage", "Garage")',
dataType: 'JSON',
data: {
name: name, countryId: countryId, garageId: garageId,
contactperson: contactperson,
phone: phone, email: email
},
success: function (data) {
if (data == "Failure") {
toastr["error"]("Error editing Garage");
}
else {
toastr["success"]("Garage successfully updated");
customerNumberOfEditingGarage = null;
refreshGrid();
}
},
error: function () {
}
});
} else {
toastr["error"]("Error editing Garage");
}
});
Method:
public bool EditGarage(GarageModel model)
{
var valid = false;
var cmd = new SqlCommand("spGarageEditGarage", Connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#GarageId", model.GarageId);
cmd.Parameters.AddWithValue("#CountryId", model.CountryId);
cmd.Parameters.AddWithValue("#ContactPerson", model.ContactPerson);
cmd.Parameters.AddWithValue("#Email", model.Email);
try
{
int result = cmd.ExecuteNonQuery();
if (result == 1)
valid = true;
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
finally
{
Connection.Close();
}
return valid;
}
Hopefully, this became a bit clearer.
I do not know what your model is and where model.GarageId comes from. If you complete the part I did not understand, you can use the following code for model.requestId.
note: Use a radiobutton instead of a checkbox.
change view to :
#using (Html.BeginForm("YourAction", "YourController", FormMethod.Post))
{
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<input type="radio" id="Claim" name="requestType" value="Claim">
<label for="Claim">Claim</label>
< </div>
</div>
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<input type="radio" id="ScheduledService" name="requestType" value="ScheduledService">
<label for="ScheduledService">ScheduledService</label>
</div>
</div>
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<input type="radio" id="Tires" name="requestType" value="Tires">
<label for="Tires">Tires</label>
</div>
</div>
<div class='form-group' style="margin-left: 60%;">
<div class="row">
<input type="submit" value="Submit"/>
</div>
</div>
</div>
}
add enum
public enum RequestType
{
Claim = 1,
ScheduledService = 2,
Tires = 3
}
in your action
public ActionResult YourAction(RequestType requestType)
{
//......................................
model.GarageId = //your value
switch (requestType)
{
case RequestType.Claim:
model.requestId = (int)RequestType.Claim;
break;
case RequestType.ScheduledService:
model.requestId = (int)RequestType.ScheduledService;
break;
case RequestType.Tires:
model.requestId = (int)RequestType.Tires;
break;
}
//get insert........................
}
I am writing a page that allows users to enter results from test pits over a period of three days.
there is a min of two test pits and a max of ten test pits.
I initially put two pits in the View and provide add and remove buttons to allow users to add more pits.
It looks like this:
I use this javascript to add more pits:
var maxPits = 10;
var minPits = 2;
var wrapper = $(".pits");
var addButton = $(".addPit");
var delButton = $(".delPit");
var x = 2;
$(addButton).click(function (e) {
e.preventDefault();
if (x < maxPits) {
x++;
$(wrapper).append('<div class="row pit' + x + '"><div class="col-sm-1">Pit ' + x + '</div><div class="col-sm-3"><input type="number" placeholder="1.234" name="pit' + x + 'day1" id="pit' + x + 'day1"></div><div class="col-sm-3"><input type="number" placeholder="1.234" name="pit' + x + 'day2" id="pit' + x + 'day2"></div><div class="col-sm-3"><input type="number" placeholder="1.234" name="pit' + x + 'day3" id="pit' + x + 'day3"></div></div>');
updatePitCount();
} else {
alert('too many pits!');
}
});
$(delButton).click(function (e) {
e.preventDefault();
if (x > minPits) {
var lastPit = '.pit' + x;
$("div").remove(lastPit);
x--;
updatePitCount();
} else {
alert('must have a minimum of two!');
}
});
My model looks like this:
public class ResultsModel
{
public List<Pit> Pits { get; set; }
}
public class Pit
{
public int Id { get; set; }
public double Day1 { get; set; }
public double Day2 { get; set; }
public double Day3 { get; set; }
public double Mean
{
get
{
var x = 0;
var total = 0.0;
if (Day1 > 0.0) { x += 1; total += Day1; }
if (Day2 > 0.0) { x += 1; total += Day2; }
if (Day3 > 0.0) { x += 1; total += Day3; }
if(x>0) return (total) / x;
return 0.0;
}
}
}
My partial view looks like this:
<div class="container pits">
<div class="row">
<div class="col-sm-1 btn-group">
<button class="btn btn-sm btn-success glyphicon glyphicon-plus addPit"></button>
<button class="btn btn-sm btn-danger glyphicon glyphicon-minus delPit"></button>
</div>
<div class="col-sm-3">
TEST 1
</div>
<div class="col-sm-3">
TEST 2
</div>
<div class="col-sm-3">
TEST 3
</div>
</div>
<div class="row">
<div class="col-sm-1">
Pit 1
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="pit1day1" />
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="pit1day2" />
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="pit1day3" />
</div>
</div>
<div class="row">
<div class="col-sm-1">
Pit 2
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="pit2day1">
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="pit2day2">
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="pit2day3">
</div>
</div>
</div>
The html is in a form that posts to a controller and I want the results from the tests to be available in the controller so that I can do some calculations on them. I am struggling to get the data from the page into the model
I want to something like this in the controller:
foreach (var pit in model.Pits)
{
var x1 = pit.Day1;
var x2 = pit.Day2;
var x3 = pit.Day3;
var m = pit.Mean;
//do something...
}
How do I get the dynamic data from the view into the controller via the model?
Any help would be appreciated.
Razor used a spatial format of name attribute when you pass the value form view to action.
Example :
If you passing
public class ResultsModel
{
public List<Pit> Pits { get; set; }
}
model into the view and receive the same then your name attribute format must like Pits[0].Day1.
so your html like
<input type="number" placeholder="1.234" name="Pits[0].Day1" />
<input type="number" placeholder="1.234" name="Pits[1].Day1" />
so one.
And one more thing use for loop rather than foreach if you use razor for generating the list of items.
If you passing
List<Pit>
into the view and receive the same then your name attribute format must like [0].Day1.
You must post data to action via a form tag!
<form method="post" action="/Pit/Create">
<div class="row">
<div class="col-sm-1">
Pit 1
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="[0].Day1" />
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="[0].Day2" />
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="[0].Day3" />
</div>
</div>
<div class="row">
<div class="col-sm-1">
Pit 2
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="[1].Day1">
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="[1].Day2">
</div>
<div class="col-sm-3">
<input type="number" placeholder="1.234" name="[1].Day3">
</div>
</div>
</form>
This partial view is used to list cart-items:
<ul class="cart-dropdown">
<li>
<div class="cart-items cart-caption">
<ul>
#foreach (var i in Model.CartItems)
{
<li id="list-item-#i.item.ItemID">
<div class="container-fluid item-wrap" style="position: relative">
<div class="item-remove">
<a href="#" class="RemoveLink"
data-id="#i.RecordID" data-itemid="#i.item.ItemID">
x
</a>
</div>
<div class="col-md-2 item-img">
<div class="row-cart">
<img alt="" id="cartImg" height="71" width="75" src="#i.item.ImageUrl">
</div>
</div>
<div class="col-md-5 item-info">
<div class="row-cart">
<div class="brand-name">
<a href="#" class="brandName">
#i.item.BrandName
</a>
</div>
<div class="product-name">
<a href="#" class="productName">
#i.item.ItemName
</a>
</div>
<div class="product-qty">
<p class="productQTY" id="item-count-#i.item.ItemID">
#i.Count x #i.item.ItemPrice
</p>
</div>
</div>
</div>
<div class="col-md-5 price-info">
<div class="row-cart" style="margin-top: 10px">
<div class="col-md-6">
<div class="row-mrp">
<span class="cartItemPrice" id="item-total-#i.item.ItemID">
Rs #(#i.Count * #i.item.ItemPrice)
</span>
</div>
</div>
</div>
</div>
</div>
</li>
}
</ul>
</div>
</li>
<li class="clearfix">
<div class="col-md-6">
<div class="row-cart sub-cost" style="background: #fff; margin-left: -10px; margin-right: 0">
<p>
Sub Total :
<span style="float: right">
Rs
<span class="ng-binding"></span>
</span>
</p>
<p>
Delivery Charge :
<span qa="delChargeMB" style="float: right">Free</span>
</p>
</div>
<div class="row-cart cart-chkout-btn">
<button type="button">View Basket & Checkout</button>
</div>
</div>
</li>
</ul>
Above partial view is rendered when user clicks on "My cart" button. I need to allow customers to remove any cart-item they like by clicking a 'remove' button inside _cartDetails.cshtml. This jQuery code is being used to accomplish this task:
$(function () {
$(".RemoveLink").click(function () {
var recordToDelete = $(this).attr("data-id");
var itemID = $(this).attr("data-itemid");
if (recordToDelete != '') {
$.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete, "itemID": itemID },
function (data) {
if (data.ItemCount == 0) {
$('#list-item-' + recordToDelete).fadeOut('slow');
}
else {
$('#item-count-' + recordToDelete).text(data.ItemCount + " x " + data.ItemPrice);
$('#item-total-' + recordToDelete).text(data.ItemCount * data.ItemPrice);
}
$('#update-message').text(data.Message);
$(".confirmItemCart").show();
$(".confirmItemCart").addClass("collapsed");
$('.confirmItemCart').delay(30000).fadeOut('slow');
$('#cart-status').text('Cart (' + data.CartCount + ')');
$('#cart-total').text(data.CartTotal);
});
}
})
});
Controller: (UPDATED)
public ActionResult cartDropDown()
{
return RedirectToAction("cartDropDownChild");
}
[ChildActionOnly]
public ActionResult cartDropDownChild()
{
var cart = ShoppingCart.GetCart(this.HttpContext);
// Set up list of cart items with total value
var viewModel = new ShoppingCartViewModel
{
CartItems = cart.GetCartItems(),
CartTotal = cart.GetTotal(),
ItemCount = cart.GetCount(),
Message = Server.HtmlEncode("There are no items in your cart. Continue shopping.")
};
foreach (var item in viewModel.CartItems)
{
item.item = db.Items.Single(i => i.ItemID == item.ItemID);
}
return PartialView("_cartDetails", viewModel);
}
This code is successfully removing items from the cart-items list but not updating the partial view (_cartDetails.cshtml). In debug mode, I've checked the values for the (data) which is returned from the ajax call and all values are correct. It is just the binding of those values with the _cartDetails html elements that is not working. Maybe I'm missing out something. Someone please guide.
Thanks in advance.
This is actually a system design related issues. Partial view gets rendered when the page loads.
When you are removing an item why don't you post to a child action which would render the same partial view and return the html. Then you can put the html in place. You do not need to handle the list-item, cart-total, cart-status etc. manually.
Add the [ChildActionOnly] filter to the action that renders the cart information section.
Then in the action: return PartialView("_cartDetails");
For example:
Move the logic from cartDropDown() function to a private function which will return a viewModel object. Then call that private function from both cartDropDown() and also in RemoveFromCart action (after deleting the data).
[ChildActionOnly]
public ActionResult cartDropDown()
{
return PartialView("_cartDetails", preparecartDropDown(this.HttpContext));
}
[ChildActionOnly]
public ActionResult RemoveFromCart(...)
{
//Delete data
return PartialView("_cartDetails", preparecartDropDown(this.HttpContext));
}
private ShoppingCartViewModel preparecartDropDown(HttpContext context)
{
var cart = ShoppingCart.GetCart(context);
var viewModel = new ShoppingCartViewModel
{
CartItems = cart.GetCartItems(),
CartTotal = cart.GetTotal(),
ItemCount = cart.GetCount(),
Message = Server.HtmlEncode("There are no items in your cart. Continue shopping.")
};
foreach (var item in viewModel.CartItems)
{
item.item = db.Items.Single(i => i.ItemID == item.ItemID);
}
return viewModel;
}
these are the actions in controller:
public ActionResult AdminRoles(int? selectedValue)
{
if (!LogedUser.InRole(Functions.User, Roles.View)) return RedirectToAction("Login");
return View(db.Users.Where(u => u.Id != 1));
}
[HttpGet]
public ActionResult GetAdminRoles(int Id)
{
var secRole = db.SecurityRoles.Where(s => s.AdminId == Id);
var func = db.SystemFunctions.ToList();
if (func.Count() > secRole.Count())
{
foreach (var item in func)
{
if (secRole.Where(s => s.SystemFunctionId == item.Id).Count() <= 0)
{
SecurityRoles sec = new SecurityRoles();
sec.AdminId = Id; sec.SystemFunctionId = item.Id;
sec.CanView = false; sec.CanAdd = false; sec.CanEdit = false; sec.CanDelete = false;
db.SecurityRoles.Add(sec);
db.SaveChanges();
}
}
}
return PartialView("GetAdminRoles",db.SecurityRoles.Where(s => s.AdminId == Id));
}
[HttpPost]
public ActionResult GetAdminRoles(int hdnAdminIDs, int[] CanView, int[] CanAdd, int[] CanEdit, int[] CanDelete)
{
var list = db.SecurityRoles.Where(o => o.AdminId == hdnAdminIDs).ToList();
foreach (var item in list)
{
if (CanView != null && CanView.Contains(item.Id))
item.CanView = true;
else
item.CanView = false;
if (CanAdd != null && CanAdd.Contains(item.Id))
item.CanAdd = true;
else
item.CanAdd = false;
if (CanEdit != null && CanEdit.Contains(item.Id))
item.CanEdit = true;
else
item.CanEdit = false;
if (CanDelete != null && CanDelete.Contains(item.Id))
item.CanDelete = true;
else
item.CanDelete = false;
}
db.SaveChanges();
return RedirectToAction("AdminRoles");
}
the following is the AdminRoles() action which include the JQuery scripts that would bring the partial view GetAdminRoles
NOTE : I tried several scripts ( between the comment marks)
#model IEnumerable<Arabawy.Models.User>
#{
ViewBag.Title = "ContactusMessages";
Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
ViewBag.CurrentURI = "/IWS/adminroles".ToLower();
}
<script>
$(function () {
#*$.get('#Url.Content("~/IWS/GetAdminRoles/")' + "?Id=" + $('#AdminIDs').val(), function (data) {
/* data is the pure html returned from action method, load it to your page */
$('#partialPlaceHolder').html(data);
/* little fade in effect */
$('#partialPlaceHolder').fadeIn('fast');
});*#
$('#AdminIDs').change(function () {
debugger
/* Get the selected value of dropdownlist */
var selectedID = $(this).val();
/* Request the partial view with .get request. */
$.get('#Url.Content("~/IWS/GetAdminRoles/")' + "?Id=" + selectedID, function (data) {
/* data is the pure html returned from action method, load it to your page */
$('#partialPlaceHolder').html(data);
/* little fade in effect */
$('#partialPlaceHolder').fadeIn('fast');
});
});
});
</script>
<div class="pages_inner_content">
<div class="title_page_start">
<div class="right_title">
<h2>صلاحيات المشرفين</h2>
<h2><span>تحديث صلاحيات المشرفين</span></h2>
</div>
<div class="left_lisks">
<ul class="links_buttons">
#{if (Arabawy.LogedUser.IsLoged() &&
Arabawy.LogedUser.InRole(Arabawy.Controllers.IWSController.Functions.User, Arabawy.Roles.Edit))
{
<li class="add_fo">
<span> حفظ </span>
</li>
}}
<li class="exit">
خروج
</li>
</ul>
</div>
</div><!--title_page_start-->
<div class="bread_cramb bread_cramb_akh_ed">
<h3> أدوات الأداره <span> صلاحيات المشرفين </span> </h3>
</div> <!--bread_cramb-->
<div class="block_in_editor">
<h3>صلاحيات المشرفين</h3>
<div style="clear:both"></div>
<div class="add_khaber_form">
#Html.ValidationSummary(false)
<hr />
<div class="blog_form_input">
<label>اختر : </label>
<select class="select" id="AdminIDs" name="AdminIDs">
<option value="" selected>< اختر المشرف ></option>
#{foreach (var item in Model)
{
<option value="#item.Id">#item.DisplayName</option>
}}
</select>
</div>
<br />
<div id="partialPlaceHolder" style="display:none;"> </div>
</div><!--add_khaber_form-->
</div><!--block_in_editor-->
</div><!--pages_inner_content-->
this is the view of GetAdminRoles
#model IEnumerable<Arabawy.Models.SecurityRoles>
<script>
function submitForm() {
$("#hdnAdminIDs").val($("#AdminIDs").val());
$('#formID').attr('target', '_self');
$("#formID").submit();
}
</script>
<form action="#Url.Action("GetAdminRoles")" target="_self" id="formID" method="post" enctype="multipart/form-data">
#Html.Hidden("hdnAdminIDs")
<div class="block_in_adv">
<div style="clear:both"></div>
<div style="clear:both"></div>
<div class="table_adv_show">
<div class="row_first color_row">
<div class="cols_mos_2">اسم الصفحة</div>
<div class="cols_mos_3">امكانية رؤية الصفحة</div>
<div class="cols_mos_3">امكانية الأضافة </div>
<div class="cols_mos_3">امكانية التعديل </div>
<div class="cols_mos_3">امكانية المسح</div>
</div><!--main_row_opi-->
<ul class="list_pages_web sortable list" id="itemContainer">
#Html.Hidden("DeletedID")
#foreach (var item in Model)
{
<li class="zoomInUp">
<div class="block_row_table">
<div class="main_row_opi_res ">
<div class="cols_mos_2">اسم الصفحة</div>
<div class="cols_mos_3">امكانية رؤية الصفحة</div>
<div class="cols_mos_3">امكانية الأضافة </div>
<div class="cols_mos_3">امكانية التعديل </div>
<div class="cols_mos_3">امكانية المسح</div>
</div><!--main_row_opi-->
<div class="main_row_opi">
<div class="cols_mos_2">#item.SystemFunction.PageName</div>
#{
string canView = item.CanView ? "checked" : "";
string CanEdit = item.CanEdit ? "checked" : "";
string CanAdd = item.CanAdd ? "checked" : "";
string CanDelete = item.CanDelete ? "checked" : "";
}
<div class="cols_mos_3">
<input type="checkbox" name="CanView" id=#string.Format("CanView" + item.Id) class="css-checkbox9 all_check" value="#item.Id" #canView /><label for=#string.Format("CanView" + item.Id) class="css-label9" checked="checked"> </label>
</div>
<div class="cols_mos_3">
<input type="checkbox" name="CanAdd" id=#string.Format("CanAdd" + item.Id) class="css-checkbox9 all_check" value="#item.Id" #CanAdd /><label for=#string.Format("CanAdd" + item.Id) class="css-label9" checked="checked"> </label>
</div>
<div class="cols_mos_3">
<input type="checkbox" name="CanEdit" id=#string.Format("CanEdit" + item.Id) class="css-checkbox9 all_check" value="#item.Id" #CanEdit /><label for=#string.Format("CanEdit" + item.Id) class="css-label9" checked="checked"> </label>
</div>
<div class="cols_mos_3">
<input type="checkbox" name="CanDelete" id=#string.Format("CanDelete" + item.Id) class="css-checkbox9 all_check" value="#item.Id" #CanDelete /><label for=#string.Format("CanDelete" + item.Id) class="css-label9" checked="checked"> </label>
</div>
</div><!--main_row_opi-->
</div><!--/*block_row_table*/-->
</li>
}
</ul>
<div class="holder"></div>
</div><!--table_adv_show-->
</div><!--block_in_adv-->
so , why my partial view does not appear in run time ???!!!!
Is there any thing wrong ???!!
please help me !!!!!!!!!!!!!!!!!!!!!
Navigate to that partial view using your browser to ascertain it is returning what you expect. Once you have made sure that is returning the expected HTML, then your code should work.
Im making PostHelper.cshtml in App_Code folder inside my Blog project. And I got this error on line:
<div class="commentsTab">
#Post.comments.Count**
</div>
and:
#foreach (tag Tag in **Post.tags**)
when Im deleting "#Post.comments.Count" its fine but Ive got similar line and there's no errors:
<div class="postTitle">#Post.Title</div>
whats wrong with this? There's whole code:
#using Blog.Models;
#helper Render(post Post, System.Web.Mvc.HtmlHelper html, bool isAdmin, bool showComments)
{
<div class="postTitle">#Post.Title</div>
<div class="postContainer">
<div class="postTabs">
<div class="dateTab">
<div class="month">#Post.DateTime.ToString("MMM").ToUpper()</div>
<div class="day">#Post.DateTime.ToString("dd")</div>
</div>
<div class="commentsTab">
#Post.comments.Count
</div>
</div>
<div class="postContent">
<div class="postBody">#html.Raw(Post.Body)</div>
<div class="tagList">
#foreach (tag Tag in Post.tags)
{
<span class="tag">#Tag.Name</span>
}
</div>
<div class="linkList">
<div id="fb-root"></div>
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/pl_PL/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</div>
</div>
</div>
if (showComments)
{
<div id="commentContainer">
<a id="comments"></a>
#foreach (comment Comment in Post.comments.OrderBy(x => x.DateTime))
{
<div class="comment">
<div class="commentName">
#if (!string.IsNullOrWhiteSpace(Comment.Email))
{
#Comment.Name
}
else
{
#Comment.Name;
}
</div>
said:
<div class="commentBody">#html.Raw(html.Encode(Comment.Body).Replace("\n", "<br/>"))</div>
<div class="commentTime">at #Comment.DateTime.ToString("HH:mm") on #Comment.DateTime.ToString("yyyy/MM/dd")</div>
</div>
}
<div id="commentEditor">
<div id="commentPrompt">Leave a comment!</div>
<form action="#Href("~/Posts/Comment/" + Post.ID)" method="post">
<input type="text" id="commentNamePrompt" name="name" /> Name (required)<br />
<input type="text" id="commentEmailPrompt" name="email" /> Email (optional)<br />
<textarea id="commentBodyInput" name="body" rows="10" cols="60"></textarea><br />
<input type="submit" id="commentSubmitInput" name="submit" value="Submit!" />
</form>
</div>
</div>
}
}
My action:
public ActionResult Index(int? id)
{
int pageNumber = id ?? 0;
IEnumerable<post> posts =
(from Post in model.posts
where Post.DateTime < DateTime.Now
orderby Post.DateTime descending
select Post).Skip(pageNumber * PostsPerPage).Take(PostsPerPage + 1);
ViewBag.IsPreviousLinkVisible = pageNumber > 0;
ViewBag.IsNextLinkVisible = posts.Count() > PostsPerPage;
ViewBag.PageNumber = pageNumber;
ViewBag.IsAdmin = IsAdmin;
return View(posts.Take(PostsPerPage));
}
I presume your exception is caused by an already open connection to the DB that you are not closing. In your case try to add a .ToList at the end of your initial select:
select Post).Skip(pageNumber * PostsPerPage).Take(PostsPerPage + 1).ToList();
This will close the reader and copy all results in your memory. See if that makes any difference.
You need MARS. Add: MultipleActiveResultSets=True; to your connection string. See: http://msdn.microsoft.com/en-us/library/ms131686.aspx