kendo button click validation messages are not showing mvc4 razor - asp.net-mvc-4

Here am using kendo button .and razor textboxes .Am not getting validation messages on button click
here is my code
<tr>
<td>
#Html.Label("User Name")
</td>
<td>
#Html.TextBoxFor(model => model.UserName, new { Class = "txtLogin" })
#Html.ValidationMessageFor(model => model.UserName)
</td>
</tr>
<tr>
<td>
#Html.Label("Password")
</td>
<td>
#Html.TextBoxFor(model => model.Password, new { Class = "txtLogin" })
#Html.ValidationMessageFor(model => model.Password)
</td>
</tr>
<tr>
<td colspan="2">
<div class="fielddiv">
#(Html.Kendo().Button()
.Name("btnsave")
.HtmlAttributes(new { type = "button" })
.Content("Login"))
</div>
</td>
</tr>

You need to check if everything is nested in a form tag (or Html.BeginForm). Then set the type of the button to "submit".

Related

ASP.NET MVC4: How to hightlight selected row and send id corresponding to controller when click on edit or detail or delete link

I need help please. I'm using ASP.NET MVC 4. I have a view(Index.cshtml) that display data in table from sql database using entity framework. I want to know how to hightlight selected row and send specific id(id_equipment) to one html.actionlink for editing, deleting or viewing details.
Here's my view:
#model IEnumerable<TEST.Models.equipment>
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
#Html.ActionLink("Edit", "Edit", new { id = /*item.id_equipment*/ }) |
#Html.ActionLink("Details", "Details", new { id = /*item.id_equipment*/ }) |
#Html.ActionLink("Delete", "Delete", new { id = /*item.id_equipment*/ })
<table>
<tr>
<th>
#Html.DisplayNameFor(model => model.id_equipment)
</th>
<th>
#Html.DisplayNameFor(model => model.name)
</th>
<th>
#Html.DisplayNameFor(model => model.type)
</th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.id_equipment)
</td>
<td>
#Html.DisplayFor(modelItem => item.name)
</td>
<td>
#Html.DisplayFor(modelItem => item.type)
</td>
</tr>
}
</table>
Thank you!

In a column of Credits, show the amount of credits for all courses for which student enlisted

How to in a column of Credits show the amount of credits for all courses for which student enlisted.
I need to modify a Contoso University app.
View:
#model PagedList.IPagedList<ContosoUniversity.Models.Student>
#using PagedList.Mvc;
<h2>Students</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
#using (Html.BeginForm("Index", "Student", FormMethod.Get))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<p>
Find by name: #Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Filter" />
</p>
}
<table class="table">
<tr>
<th>
#Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.NameSortParm })
</th>
<th>
First Name
</th>
<th>
#Html.ActionLink("Enrollment Date", "Index", new { sortOrder = ViewBag.DateSortParm })
</th>
<th>
Date Of Birth
</th>
<th>
Courses
</th>
<th>
Credits
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.FirstMidName)
</td>
<td>
#Html.DisplayFor(modelItem => item.EnrollmentDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.DateOfBirth)
</td>
<td>
#string.Join(",", item.Enrollments.Select(e => e.Course.Title))
</td>
<td>
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
#Html.ActionLink("Details", "Details", new { id=item.ID }) |
#Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
<br />
Page #(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of #Model.PageCount
#Html.PagedListPager(Model, page => Url.Action("Index",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
Please Help!
I dont understand how to do it!
If somebody need more details please tell me.
I don't have any experience with Contoso University, but it seems to me that you may be able to sum the credits by doing something like this:
item.Enrollments.Sum(e => e.Course.Credits);
This is untested and it's hard to know for sure if this will work without knowing how the data is structured, but I'm sure looking at the Sum() method will help you out.
#item.Enrollments.Sum(e => e.Course.Credits)

Issue Saving Edited Data: DDL Value can not be null

I am having an issue with saving the edited fields in my MVC project. When I click the submit button I get an error
Value cannot be null.
Parameter name: items
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: items
Source Error:
Line 63:
Line 64:
Line 65: #Html.DropDownListFor(model => model.EventTypeID, new SelectList(ViewBag.EventTypes, "EventTypeID", "EventType1"), "Choose")
Line 66:
Line 67:
I have tried some things that I have seen on the internet but it doesn't seem to be doing anything for me :( Help would be appreciated thank you!
this is my controller When I put a break point here it never triggers.
[HttpPost]
public ActionResult IndexPST(Event_Setup es)
{
db.Event_Setup.Add(es);
db.SaveChanges();
return View("Index",es);
}
And this is my View
#model DixonGroupInc.Models.Event_Setup
<link href="~/Content/EventManagement.css" rel="stylesheet" />
#using (Html.BeginForm("IndexPST", "EventManagement", FormMethod.Post))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<div id="cntr">
<div id="emLoc">
<table id="ldTbl">
<thead>
<tr>
<th class="ln">
<img src="~/Images/4.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="chosen space">EventMetadata
</td>
<td class="space">Client / Vendor
</td>
<td class="space">Venu info
</td>
<td class="space">Sponsored Participants
</td>
<td class="space">Event Services
</td>
</tr>
</tbody>
</table>
</div>
<div id="emSetup">
Setup Meeting
</div>
<div id="emTable">
<table class="myTbl">
<tr>
<td class="lblEvent clm1">
#Html.Label("Event Type")
</td>
<td class="clm2">
#Html.DropDownListFor(model => model.EventTypeID, new SelectList(ViewBag.EventTypes, "EventTypeID", "EventType1"), "Choose")
</td>
<td class="clm3">
#{Html.RenderAction("EventType", "EventManagement");}
</td>
</tr>
<tr class="rows">
<td class="lblEvent clm1">
#Html.Label("Event Title")
</td>
<td class="clm2">
#Html.EditorFor(model => model.EventTitle)
#Html.ValidationMessageFor(model => model.EventTitle)
</td>
</tr>
<tr>
<td class="lblEvent clm1">
#Html.Label("Event Identifier")
</td>
<td class="clm2">
#Html.EditorFor(model => model.EventIdentifier)
#Html.ValidationMessageFor(model => model.EventIdentifier)
</td>
</tr>
</table>
<table class="dateTbl">
<tr class="rows">
<td class="lblEvent clm1">
#Html.Label("Event Date From")
</td>
<td class="clm2">
#Html.TextBoxFor(model => model.EventDateFrom, new { #class = "dateFrom" })
#Html.ValidationMessageFor(model => model.EventDateFrom)
</td>
<td class="lblEvent">
#Html.Label("To")
</td>
<td class="clm4">
#Html.TextBoxFor(model => model.EventDateTo, new { #class = "dateTo" })
#Html.ValidationMessageFor(model => model.EventDateTo)
</td>
</tr>
</table>
<table class="myTbl">
<tr>
<td class="lblEvent clm1">
#Html.Label("Event Description")
</td>
<td class="clm2">
#Html.TextAreaFor(model => model.EventDescription, new
{
id = "taED"
})
<div>
<span id="charLeft2"></span>characters remaining.
</div>
#Html.ValidationMessageFor(model => model.EventDescription)
</td>
</tr>
<tr class="rows">
<td class="lblEvent clm1">
#Html.Label("Custom Message")
</td>
<td class="clm2">
#Html.TextAreaFor(model => model.CustomMessage, new
{
id = "taCM"
})
<div>
<span id="charLeft1"></span>characters remaining.
</div>
#Html.ValidationMessageFor(model => model.CustomMessage)
</td>
</tr>
<tr>
<td class="lblEvent clm1">
#Html.Label("Instructions")
</td>
<td class="clm2">
#Html.TextAreaFor(model => model.Instructions, new
{
id = "taInstrct"
})
<div>
<span id="charLeft"></span>characters remaining.
</div>
#Html.ValidationMessageFor(model => model.Instructions)
</td>
</tr>
</table>
<table class="myTbl">
<tr class="rows">
<td>
#{Html.RenderAction("AddTrack", "EventManagement");}
</td>
</tr>
<tr>
<td>
#{Html.RenderAction("EventTrack", "EventManagement");}
</td>
</tr>
</table>
<table class="myTbl">
<tr class="rows">
<td class="lblEvent clm1">
#Html.Label("CFP Pocess")
</td>
<td class="clm2">
#Html.RadioButtonFor(model => model.CFPRequired, "true") Yes
</td>
<td class="clm3">
#Html.RadioButtonFor(model => model.CFPRequired, "false") No
</td>
</tr>
</table>
</div>
<div id="emSubmit">
<input type="submit" value="Save & Next" id="submit" />
</div>
</div>
}
Viewbag can be unreliable so generally it isn't recommended to pass your drop down list data through the viewbag. I would recommend adding it to your view model instead. In your Event_Setup class make sure that you have
public int EventTypeID { get; set; }
and
public List<SelectListItem> EventTypeList { get; set; }
on your controller get you can set EventTypeID to set a default on the drop down so your controller should have something like
Event_Setup es = new Event_Setup();
es.EventTypeID = //default value if you want;
es.EventTypeList = //Method call here where List<SelectListItem> is returned with your event list
then on your view you can change your drop down to
#Html.DropDownListFor(x => x.EventTypeID, Model.EventTypeList)

When returning a view to an iframe in MVC4, the viewbag, viewdata, or tempdata doesnt pass information back to the overall view.

I have a view that has some dropdowns that allows you to choose some surveys. When selected it loads the survey into an iframe. Loading the view into it works fine, but I am trying to display stats (summary) about this survey alongside the iframe. But since I'm returning the view to the iframe, the viewbag, viewdata, or tempdata doesnt return anything (imagine it does to the iframe), but I need it to return information to the overall view. Not sure how to do this.. Any help is greatly appreciated. Thanks
My view:
#using (Html.BeginForm("Survey", "Moderator", FormMethod.Post, new { target = modFrame" }))
{
<div id="jWizard" class="jWizard wizardStyle">
<table class="moderatorPage">
<tr>
<td > </td>
<td> </td>
<td> </td>
<td> </td>
<td>Study: #Html.DropDownList("SurveyID", Model.Surveys, new { onchange = "LoadGroups();", #class = "dropDownMain" })</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>Group: #Html.DropDownList("GroupID", Model.UserGroups, new { onchange = "LoadUsers();", #class = "dropDownMain" })</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>User: #Html.DropDownList("UserID", Model.Users, new { #class = "dropDownMain" })</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="submit" value="Start" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><iframe id="modFrame" name="modFrame" style="width:100%; height:1000px; border:0px"></iframe></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>#TempData["test"]</td>
<td>#ViewBag.test</td>
<td>#ViewData["test"]</td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
}
And in my controller:
public ActionResult Survey(int SurveyID, string GroupID, string UserID)
{
ViewBag.UserID = UserID;
if (SurveyID != 0)
{
TempData["test"] = "test1";
ViewData["test"] = "test2";
ViewBag.test = "test3";
var userTypeRepo = new UserTypeRepository(new UnitOfWork());
ViewBag.UserType = userTypeRepo.Get(user.UserTypeID).Description;
var repo = new SurveyRepository(new UnitOfWork());
var survey = repo.Get(SurveyID, "MasterPages,MasterPages.MasterTickets");
return View(survey);
}
else
{
return View("Error", (object)"Survey ID is zero");
}
}
Welcome to Stackoverflow!
The ViewBag in your iframe is not exposed to the ViewBagin your hosting page. In fact, you will need a page refresh in the hosting page to reload it's own ViewBag.
If I were you, I would re-architect the solution to make use of ajax services and a view engine based on JavaScript (e.g. AngularJS) to retrieve your dynamic data; however, if there is some reason that you have to stick with this iFrame approach, then you probably need to just reload your entire page on a selection change, populate the host page's viewbag with the relevant data, and set the source of the iframe with a ViewBag parameter as well.
Good luck!

Accordion within table rows

I am using Twitter Bootstrap. Currently I am working on Master Details looks alike table, which I am planning to place an accordion into each table's row and if it is expanded, the partial view will be reload and displayed.
Somehow it does not work as expected but if I change it to Modal, the partial view loaded perfectly.
This is the controller that process and returning the values:
public ActionResult Index(int id,int? page)
{
List<CustomerProduct> customerProducts =
(from c in RepositoryProduct.Reload(id)
select c).ToList<CustomerProduct>();
return PartialView("_CustomerProducts", customerProducts);
}
and this is the table in the view :
<table id="tbl" class="table table-condensed" style="border-collapse:collapse;">
<thead>
<tr>
<th>
#Html.ActionLink("Customer Name", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
#Html.DisplayNameFor(model => model.First().CustLocalName)
</th>
<th>
#Html.ActionLink("Country", "Index", new { sortOrder = ViewBag.CountrySortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
#Html.DisplayNameFor(model => model.First().City)
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr data-toggle="collapse">
<td style="display:none;">
#Html.DisplayFor(modelItem => item.CustID)
</td>
<td>
#Html.DisplayFor(modelItem => item.CustName)
</td>
<td>
#Html.DisplayFor(modelItem => item.CustLocalName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Country.CountryName)
</td>
<td>
#Html.DisplayFor(modelItem => item.City)
</td>
<td>
<a class="btn btn-small btn-info" type="button" href="#Url.Action("Index", "CustomerProduct", new { id = item.CustID })" data-toggle="collapse" data-target="##item.CustID" >Products</a>
</td>
</tr>
<tr>
<td colspan="6" class="hiddenRow">
<div id="#item.CustID" class="accordian-body collapse" tabindex="-1">
<div class="accordion-header">
<label>
<strong>#item.CustName product(s)</strong>
</label>
</div>
<div class="accordion-body">TEST</div>
</div>
</td>
</tr>
}
</tbody>
</table>
this is part of the code that calling the controller Index function :
<a class="btn btn-small btn-info" type="button" href="#Url.Action("Index", "CustomerProduct", new { id = item.CustID })" data-toggle="collapse" data-target="##item.CustID" >Products</a>
Actually I would like to load the partialview(_CustomerProduct) in the div class="accordion-body" as what I did in div class="modal-body" but no success. May I know if it is possible to do it and if yes, may I know how?
Any help will be appreciated.
for me to get the view to work i used
<td colspan="6" class="hiddenRow">
<div id="#item.CustID" class="accordian-body collapse" tabindex="-1">
<div class="accordion-header">
<label>
<strong>#item.CustName product(s)</strong>
</label>
</div>
<div class="accordion-body">
#Html.Partial("_CustomerProduct")
</div>
</div>
</td>