Nop Commerce RenderBootstrapTabHeader Submit - c#

I have the following code in a custom plugin in NopCommerce v3.8.
#using Nop.Web.Framework;
#using Nop.Core;
#using System.Linq;
#using Nop.Web.Framework.UI;
#using Nop.Web.Framework;
#using Nop.Core.Infrastructure;
#model Nop.Plugin.Widgets.PromoSlider.Domain.PromoSliderRecord
#{ Layout = "_AdminLayout.cshtml"; }
<div class="content">
<div class="form-horizontal">
<div id="slider-edit" class="nav-tabs-custom">
<ul class="nav nav-tabs">
#Html.RenderBootstrapTabHeader("Slider", #T("Slider"), true)
#Html.RenderBootstrapTabHeader("Images", #T("Images"))
</ul>
<div class="tab-content">
#Html.RenderBootstrapTabContent("Slider", Sliders(), true)
#Html.RenderBootstrapTabContent("Images", Images(), false)
</div>
</div>
</div>
</div>
#helper Sliders()
{
using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">
<div>
<div class="adminData">#Html.HiddenFor(m => m.PromoSliderId)</div>
</div>
<div class="form-group">
<div class="col-md-2">#Html.NopLabelFor(m => m.PromoSliderName)</div>
<div class="col-md-9">
#Html.EditorFor(m => m.PromoSliderName)
#Html.ValidationMessageFor(m => m.PromoSliderName)
</div>
</div>
<div class="form-group">
<div class="col-md-2">#Html.NopLabelFor(m => m.IsActive) </div>
<div class="col-md-9">
#Html.EditorFor(m => m.IsActive)
#Html.ValidationMessageFor(m => m.IsActive)
</div>
</div>
<div class="form-group">
<div class="col-md-2">#Html.NopLabelFor(m => m.Interval)</div>
<div class="col-md-9">
#Html.EditorFor(m => m.Interval)
#Html.ValidationMessageFor(m => m.Interval)
</div>
</div>
<div class="form-group">
<div class="col-md-2">#Html.NopLabelFor(m => m.Wrap)</div>
<div class="col-md-9">
#Html.EditorFor(m => m.Wrap)
#Html.ValidationMessageFor(m => m.Wrap)
</div>
</div>
<div class="form-group">
<div class="col-md-2">#Html.NopLabelFor(m => m.PauseOnHover)</div>
<div class="col-md-9">
#Html.EditorFor(m => m.PauseOnHover)
#Html.ValidationMessageFor(m => m.PauseOnHover)
</div>
</div>
<div class="form-group">
<div class="col-md-2">#Html.NopLabelFor(m => m.ZoneName)</div>
<div class="col-md-9">
#Html.DropDownListFor(m => m.ZoneName, new SelectList(
new List<string>() {
"producdivetails_top",
"categorydetails_after_breadcrumb",
"home_page_top"
}))
#Html.ValidationMessageFor(m => m.ZoneName)
</div>
</div>
<div class="pull-right">
<button type="submit" name="save" class="btn bg-blue">
<i class="fa fa-floppy-o"></i>
#T("DERP")
</button>
</div>
</div>
</div>
</div>
}
}
#helper Images()
{
if (Model.PromoSliderId > 0)
{
#Html.Action("ManagePromoImages", new { PromoSliderId = Model.PromoSliderId })
}
else
{
<p>Please create and save a slider first.</p>
}
}
Submit button doesnt fire at all, reason can be found by looking at the generated source.
<div class="content">
<div class="form-horizontal">
<div id="slider-edit" class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active"><a data-tab-name="Slider" data-toggle="tab" href="#Slider">slider</a></li>
<li class=""><a data-tab-name="Images" data-toggle="tab" href="#Images">images</a></li>
</ul>
<div class="tab-content">
<form action="/PromoSlider/CreateUpdatePromoSlider" method="post"></form><div class="tab-pane active" id="Slider"><input name="__RequestVerificationToken" type="hidden" value="uH2GbG4t6n0dDyBs79d6GQZTorBRpgWFCFithR77gSkAUYvPkMecNIwYtkEGyayid97gmdQp-isUUkMq1M7qSpeYOzwLGW-9WtUIxggkBd-0gATnIt5CvfEtUpjqwnl90" /> <div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">
<div>....
As you can see for some mad reason it decideds to create the form, then close it and input all the #helper html code including the submit button, after the form.
My question, Can you still use
#Html.BeginForm
inside of the
#Html.RenderBootstrapTabHeader
Really would like to get this working in 3.8 thanks.

The only way which I can offer now is to use <form></form> tag with required parameters to create a form inside #helper {}.
We have created an appropriate issue to investigate this problem:
https://github.com/nopSolutions/nopCommerce/issues/1840

Related

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[AVASupplierPortal.Models.PurchaseOrder]' [duplicate]

This question already has answers here:
The model item passed into the dictionary is of type .. but this dictionary requires a model item of type
(7 answers)
Closed 5 years ago.
In my MVC project im getting error while returning the particular
System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[AVASupplierPortal.Models.PurchaseOrder]', but this dictionary requires a model item of type 'AVASupplierPortal.Models.PurchaseOrder'.
How to display the list data's to view?
#model AVASupplierPortal.Models.PurchaseOrder
#{
ViewBag.Title = "Edit";
}
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
#Html.HiddenFor(model => model.POID)
<div class="shipment_innercontainer">
<div class="shipe_header-details">
<div class="shipe_header_list">
<div class="shipe_list">
<label>PO #</label>
<label>#Html.DisplayFor(model => model.PONumber)</label>
</div>
<div class="shipe_list">
<label>Carrier</label>
<label>#Html.DisplayFor(model => model.Carrier)</label>
</div>
<div class="shipe_list">
<label>Shipment Type</label>
<label><span class="ship_icon shippingicons icontext">#Html.DisplayFor(model => model.ShipmentType)</span></label>
</div>
</div>
<div class="shipe_header_list">
<div class="shipe_list">
<label>PO Date</label>
<label> #Convert.ToString(string.Format("{0:dd/MM/yyyy}", Model.PODate))</label>
</div>
<div class="shipe_list">
<label>Status</label>
<label>#Html.DisplayFor(model => model.POStatusDetails.OrderByDescending(p => p.StatusID).First().MSTPOStatu.POStatus)</label>
</div>
<div class="shipe_list">
<label>Branch Name</label>
<label>#Html.DisplayFor(model => model.BranchName)</label>
</div>
</div>
<div class="shipe_header_list">
<div class="shipe_list">
<label>Retailer</label>
<label>#Html.DisplayFor(model => model.MSTRetailerDetail.RetailerName)</label>
</div>
<div class="shipe_list">
<label>File #</label>
<label>#Html.DisplayFor(model => model.FileDetail)</label>
</div>
<div class="shipe_list">
<label>Customer #</label>
<label>#Html.DisplayFor(model => model.Customer)</label>
</div>
</div>
</div>
<div class="Options-Header">
<div>
<div class="Options"> <span><img src="~/Content/Images/Save_Icon.PNG" alt="Save" /></span> <span>Save</span> </div>
<div class="Options"> <span><img src="~/Content/Images/Print_Icon.PNG" alt="Print" /></span> <span>Print</span> </div>
<div class="Options"> <span><img src="~/Content/Images/History_Icon.PNG" alt="History" /></span> <span>History</span> </div>
</div>
</div>
<div class="TabsContainer">
<ul>
<li class="Tab-ISF Tab-Active">Purchase Order</li>
<li class="Tab-BaseFile">Acknowledgement</li>
<li class="Tab-7501">ASN</li>
<li class="Tab-DeliverOrder">Invoice</li>
</ul>
</div>
<div class="shipment_forms">
<div class="Content_Heading">
<h1>Purchase Order Details</h1>
</div>
<form>
<div class="PersonalFormFields">
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Requisition Number</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.RequistionNumber) </label>
<input type="text" value=#Html.DisplayFor(model => model.RequistionNumber) style="display:none" />
<div class="FORM_ERROR"> <span>Please Enter Requisition No</span> </div>
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Contact Name</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.ContactName)</label>
<input type="text" value=#Html.DisplayFor(model => model.ContactName) style="display:none" />
<div class="FORM_ERROR"> <span>Please Enter Contact Name</span> </div>
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Due Date</span> </div>
<div class="FORM_ENTRY Date_Pick">
<label>#Convert.ToString(string.Format("{0:dd/MM/yyyy}", Model.DueDate))</label>
<input type="text" id="datepicker" value=#Html.DisplayFor(model => model.DueDate) style="display:none" />
<span class="date_icon" style="display:none"></span>
<div class="FORM_ERROR"> <span>This Must Be Field Out</span> </div>
</div>
</div>
</div>
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Status</span> </div>
<div class="FORM_ENTRY">
<select id="test" class="speed">
<option>Acknowledged</option>
<option>ASN Sent</option>
<option>Invoice Sent</option>
</select>
<div class="FORM_ERROR"> <span>This Must Be Field Out</span> </div>
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Tracking Number</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.TrackingNumber)</label>
<input type="text" value=#Html.DisplayFor(model => model.TrackingNumber) style="display:none" />
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Phone</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.Phone)</label>
<input type="text" value=#Html.DisplayFor(model => model.Phone) style="display:none" />
</div>
</div>
</div>
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Fax</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.Fax)</label>
<input type="text" value=#Html.DisplayFor(model => model.Fax) style="display:none" />
</div>
</div>
</div>
</div>
</form>
</div>
<div class="shipment_forms">
<div class="Content_Heading">
<h1>Address Information</h1>
</div>
<form>
<div class="PersonalFormFields">
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Bill To</span> </div>
<div class="FORM_ENTRY">
<select class="speed">
<option>Select</option>
<option>Administrator</option>
</select>
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Billing Address</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POBillToAddress.POBillingAddress)</label>
<textarea style="display:none"></textarea>
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Billing City</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POBillToAddress.POBillingCity)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
</div>
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Billing State</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POBillToAddress.POBillingState)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Billing Code</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POBillToAddress.POBillingCode)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Billing Country</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POBillToAddress.POBillingCountry)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
</div>
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Deliver To</span> </div>
<div class="FORM_ENTRY">
<input type="text" value="" style="display:none" />
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Shipping Address</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POShipToAddress.POShippingAddress)</label>
<textarea style="display:none"></textarea>
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Shipping City</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POShipToAddress.POShippingCity)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
</div>
<div class="EPE_FORM_Container">
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Shipping State</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POShipToAddress.POShippingState)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Shipping Code</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POShipToAddress.POShippingCode)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
<div class="FORM_PANEL">
<div class="FORM_FIELD"> <span>Shipping Country</span> </div>
<div class="FORM_ENTRY">
<label>#Html.DisplayFor(model => model.POShipToAddress.POShippingCountry)</label>
<input type="text" value="" style="display:none" />
</div>
</div>
</div>
</div>
</form>
</div>
<div class="sf15_sf20_tables">
<div class="Bill_Heading">
<h1>Product Details</h1>
</div>
<div class="sf_container Bill_Info">
<div class="sf_table-part deliverT">
<table class="table ProjectTable deliverytable">
<tr>
<th>Product</th>
<th>Retailer Product Number</th>
<th>Notes</th>
<th>Qty</th>
<th>Unit Cost</th>
<th>Retailer Price</th>
<th>Discount(%)</th>
<th>Total</th>
<th>Action</th>
</tr>
#foreach (var lineItems in Model.POLineItemDetails)
{
<tr>
<td>#Html.DisplayFor(modelItem => lineItems.ItemDescription)</td>
<td>#Html.DisplayFor(modelItem => lineItems.RetailerItemNumber)</td>
<td>#Html.DisplayFor(modelItem => lineItems.Notes)</td>
<td>#Html.DisplayFor(modelItem => lineItems.Quantity)</td>
<td>#Html.DisplayFor(modelItem => lineItems.UnitCost)</td>
<td>#Html.DisplayFor(modelItem => lineItems.RetailerPrice)</td>
<td>#Html.DisplayFor(modelItem => lineItems.Discount)</td>
<td>#Html.DisplayFor(modelItem => lineItems.Total)</td>
<td><span class="delete_icon1"></span></td>
</tr>
}
</table>
</div>
</div>
</div>
<div class="form-group" style="display:none">
#Html.LabelFor(model => model.PONumber, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.PONumber, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.PONumber, "", new { #class = "text-danger" })
</div>
</div>
<div class="shipment_forms">
<div class="Content_Heading">
<h1>Terms & Conditions</h1>
</div>
<div class="PersonalFormFields">
<div class="EPE_FORM_Container">
<div class="FORM_PANEL full-width-textarea">
<div class="FORM_FIELD"> <span>Terms & Conditions</span> </div>
<div class="FORM_ENTRY">
<div class="form-group">
<div class="col-md-10">
#Html.EditorFor(model => model.TermsAndConditions, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="shipment_forms">
<div class="Content_Heading">
<h1>Description Informations</h1>
</div>
<div class="PersonalFormFields">
<div class="EPE_FORM_Container">
<div class="FORM_PANEL full-width-textarea">
<div class="FORM_FIELD"> <span>Description</span> </div>
<div class="FORM_ENTRY">
<div class="form-group">
<div class="col-md-10">
#Html.EditorFor(model => model.Description, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="SearchButtonAdvance formbutton">
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
</div>
</div>
}
#*<div>
#Html.ActionLink("Back to List", "Index")
</div>*#
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
In the controller:
When you do
View(*THIS IS YOUR MODEL*)
In the View
#model *THIS IS YOUR MODEL*
Those two things need to match, otherwise you get that error. Like oppassum said, read the error:
The model item passed into the dictionary is of
type 'System.Collections.Generic.List`1[AVASupplierPortal.Models.PurchaseOrder]',
but this dictionary requires a model item of
type 'AVASupplierPortal.Models.PurchaseOrder'.
List vs. single item.
Welcome to StackOverflow :)

mvc edit return value but db doesnt update

i have mvc project to register new student and give him courses and degree,etc, as shown in the database(i use entity framework) database of the project
. the edit view code is :
#model IList<HighStudy.Models.Grade>
#{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title" align="center">Student Info</h3>
</div>
<div class="panel-body">
<div class="col-lg-4">
<p>Name: #Html.DisplayFor(model => model[0].Student.Name)</p>
<p>Level: #Html.DisplayFor(model => model[0].Student.Level)</p>
</div>
<div class="col-lg-4">
<p>Department: #Html.DisplayFor(model => model[0].Student.Department)</p>
<p>Study Type: #Html.DisplayFor(model => model[0].Student.StudyType)</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title" align="center">Course 1</h3>
</div>
<div class="panel-body">
<ul class="list-group">
#for (var i = 0; i < Model.Count; i++)
{
if (Model[i].CourseNumber == 1)
{
if (Model[i].Mark == "A" || Model[i].Mark == "B")
{
<li class="list-group-item list-group-item-success">
<div class="row">
<div class="col-lg-8">
#Model[i].Cours.Course_Title
#Html.TextBoxFor(model => Model[i].Cours.Course_Title, new { style = "width:50%" })
#Html.ValidationMessageFor(model => Model[i].Cours.Course_Title)
</div>
<div class="col-lg-2">
#Model[i].Grade1
#Html.TextBoxFor(model => Model[i].Grade1, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Grade1)
</div>
<div class="col-lg-2">
#Model[i].Mark
#Html.TextBoxFor(model => Model[i].Mark, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Mark)
</div>
</div>
</li>
}
else
{
<li class="list-group-item list-group-item-danger">
<div class="row">
<div class="row">
<div class="col-lg-8">
#Model[i].Cours.Course_Title
#Html.TextBoxFor(model => Model[i].Cours.Course_Title, new { style = "width:50%" })
#Html.ValidationMessageFor(model => Model[i].Cours.Course_Title)
</div>
<div class="col-lg-2">
#Model[i].Grade1
#Html.TextBoxFor(model => Model[i].Grade1, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Grade1)
</div>
<div class="col-lg-2">
#Model[i].Mark
#Html.TextBoxFor(model => Model[i].Mark, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Mark)
</div>
</div>
</div>
</li>
}
}
}
</ul>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title" align="center">Course 2</h3>
</div>
<div class="panel-body">
<ul class="list-group">
#for (var i = 0; i < Model.Count; i++)
{
if (Model[i].CourseNumber == 2)
{
if (Model[i].Mark == "A" || Model[i].Mark == "B")
{
<li class="list-group-item list-group-item-success">
<div class="row">
<div class="col-lg-8">
#Model[i].Cours.Course_Title
#Html.TextBoxFor(model => Model[i].Cours.Course_Title, new { style = "width:50%" })
#Html.ValidationMessageFor(model => Model[i].Cours.Course_Title)
</div>
<div class="col-lg-2">
#Model[i].Grade1
#Html.TextBoxFor(model => Model[i].Grade1, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Grade1)
</div>
<div class="col-lg-2">
#Model[i].Mark
#Html.TextBoxFor(model => Model[i].Mark, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Mark)
</div>
</div>
</li>
}
else
{
<li class="list-group-item list-group-item-danger">
<div class="row">
<div class="col-lg-8">
#Model[i].Cours.Course_Title
#Html.TextBoxFor(model => Model[i].Cours.Course_Title, new { style = "width:50%" })
#Html.ValidationMessageFor(model => Model[i].Cours.Course_Title)
</div>
<div class="col-lg-2">
#Model[i].Grade1
#Html.TextBoxFor(model => Model[i].Grade1, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Grade1)
</div>
<div class="col-lg-2">
#Model[i].Mark
#Html.TextBoxFor(model => Model[i].Mark, new { style = "width:30px" })
#Html.ValidationMessageFor(model => Model[i].Mark)
</div>
</div>
</li>
}
}
}
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<input type="submit" value="Save" class="btn btn-default" />
</div>
}
<div class="col-lg-offset-0">
#Html.ActionLink("Back to List", "Index")
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
and in the controller code for the edit view is :
edit view code in the controller
. when it reach db.Entry(g).State = System.Data.Entity.EntityState.Modified;
it goes to catch block!!
any help will be useful, thanks in advance.
I believe you should iterate over your collection to add each object to the context, and set it to Modified.
foreach(grade in g)
{
db.Entry(grade).State = EntityState.Modified;
}
db.SaveChanges();
You must do SaveChanges outside the foreach statement
db.Entry(g).State = System.Data.Entity.EntityState.Modified;
In the above code you are getting g from another object, you need to originate it from the same db object which you are using to change the State
another things could be the list, I think state of List can't be modified altogether.
consider doing something like this
foreach (var item in g)
{
db.Set<Grade>().Attach(item);
db.Entry<Grade>(item).State = EntityState.Modified;
db.Configuration.ValidateOnSaveEnabled = false;
}
db.SaveChanges();
Recently gone through the same error, and foreach saved my life. Not sure if its a very clean way to do it.
SOLVED
my current exception was :
( Unable to update the EntitySet - because it has a DefiningQuery and no element exists in the element to support the current operation
steps that solve it :
delete all duplicate #html.hiddenfor(model=> model.StudentID) in the edit view
Right click on .edmx file and chose open with xml editor
search for DefiningQuery and Remove it, yes Remove it
search for ( store:Schema="dbo" ) and rename it to ( Schema="dbo" )
these were the steps that saved my life, thank you all my friends for help, i really appreciate your help

Styling Kendo Window's content with Bootstrap

I have a generic Kendo Window that I call for different partial views. I can't style contents using bootstrap, as it causes different layouts in different browsers and elements are always cluttered.
This is a sample:
<div class="form-group form-inline">
<div class="line">
<div class="col-xs-6">
#Html.LabelFor(m => m.2, new { #class = "col-xs-4 control-label" })
#Html.DisplayFor(m => m.2)
</div>
<div class="col-xs-4">
#Html.LabelFor(m => m.3, new { #class = "col-xs-4 control-label" })
#Html.DisplayFor(m => m.3)
</div>
</div>
<div class="line">
<div class="col-xs-6">
#Html.LabelFor(m => m.4, new { #class = "col-xs-4 control-label" })
#Html.DisplayFor(m => m.4)
</div>
<div class="col-xs-4">
#Html.LabelFor(m => m.5, new { #class = "col-xs-4 control-label" })
#Html.DisplayFor(m => m.5)
</div>
</div>
</div>
<div class="clearfix"> </div>
<div class="clearfix"> </div>
#(Html.Kendo().Grid<Class...>()
....
And line:
.line{
line-height: 20px;
}
Am I missing something? I just want to have a 2-column layout. Can you give me an example please?
I don't know why, but I should use col-xs-5. Also, to keep elements inside a tab strip I have to put them inside a container.
<div class="container-fluid">
<div class="form-group form-inline col-xs-12">
<div class="col-xs-5"></div>
<div class="col-xs-5"></div>
</div>
<div class="form-group form-inline col-xs-12">
<div class="col-xs-5"></div>
<div class="col-xs-5"></div>
</div>
......
</div>
UPDATE
I found the solution at their documents.
First you need to add the following references.
<link rel="stylesheet" href="http://cdn.kendostatic.com/VERSION/styles/kendo.common-bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/VERSION/styles/kendo.bootstrap.min.css">
And then add the following CSS to your site.css and include it in the page:
/* reset everything to the default box model */
*, :before, :after
{
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
/* set a border-box model only to elements that need it */
.form-control, /* if this class is applied to a Kendo UI widget, its layout may change */
.container,
.container-fluid,
.row,
.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1,
.col-xs-2, .col-sm-2, .col-md-2, .col-lg-2,
.col-xs-3, .col-sm-3, .col-md-3, .col-lg-3,
.col-xs-4, .col-sm-4, .col-md-4, .col-lg-4,
.col-xs-5, .col-sm-5, .col-md-5, .col-lg-5,
.col-xs-6, .col-sm-6, .col-md-6, .col-lg-6,
.col-xs-7, .col-sm-7, .col-md-7, .col-lg-7,
.col-xs-8, .col-sm-8, .col-md-8, .col-lg-8,
.col-xs-9, .col-sm-9, .col-md-9, .col-lg-9,
.col-xs-10, .col-sm-10, .col-md-10, .col-lg-10,
.col-xs-11, .col-sm-11, .col-md-11, .col-lg-11,
.col-xs-12, .col-sm-12, .col-md-12, .col-lg-12
{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
And everything works fine, you should be able to use the following:
<div class="container-fluid">
<div class="form-group form-inline col-xs-12">
<div class="col-xs-6"></div>
<div class="col-xs-6"></div>
</div>
<div class="form-group form-inline col-xs-12">
<div class="col-xs-6"></div>
<div class="col-xs-6"></div>
</div>
......
</div>
You'll probably need something like this. Play with the column widths depending on your labels.
<div class="form-group form-inline">
<div class="col-xs-6">
#Html.LabelFor(m => m.2, new { #class = "control-label" })
</div>
<div class="col-xs-6">
#Html.DisplayFor(m => m.2)
</div>
</div>
<div class="form-group form-inline">
<div class="col-xs-6">
#Html.LabelFor(m => m.3, new { #class = "control-label" })
</div>
<div class="col-xs-6">
#Html.DisplayFor(m => m.3)
</div>
</div>
<div class="form-group form-inline">
<div class="col-xs-6">
#Html.LabelFor(m => m.4, new { #class = "control-label" })
</div>
<div class="col-xs-6">
#Html.DisplayFor(m => m.4)
</div>
</div>
<div class="form-group form-inline">
<div class="col-xs-6">
#Html.LabelFor(m => m.5, new { #class = "control-label" })
</div>
<div class="col-xs-6">
#Html.DisplayFor(m => m.5)
</div>
</div>

ASP MVC Grid with edit modal

I'm using MVC 4 and Entity Framework and Grid.MVC for datagrid.
I have tried to implement a modal dialog to edit records using bootstrap.
When i click edit, modal window does not appear.
I follow the instruction how to create modal here:
Popup dialog for editing record using Grid.MVC in a ASP.NET MVC3
here is my code
YOU CAN DOWNLOAD MY SAMPLE PROJECT HERE
HomeController
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult HR201()
{
DCHREmployee dchremp = new DCHREmployee();
List<HREmployee> hrempList = new List<HREmployee>();
foreach (HREmployee hremp_ in dchremp.GetHREmployee(""))
{
hrempList.Add(hremp_);
}
return View(hrempList);
}
[HttpGet]
public ActionResult Edit(String EmpID)
{
DCHREmployee dchremp = new DCHREmployee();
List<HREmployee> hrempList = new List<HREmployee>();
foreach (HREmployee hremp_ in dchremp.GetHREmployee(EmpID))
{
hrempList.Add(hremp_);
}
return View(hrempList[0]);
}
}
HR201 cshtml view
#model IEnumerable<TAObjectModel.HREmployee>
#using GridMvc.Html
#using TAObjectModel
#{
ViewBag.Title = "HR201";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="#Url.Content("~/Content/Gridmvc.css")" rel="stylesheet" />
<link href="#Url.Content("~/Content/bootstrap.min.css")" rel="stylesheet" />
<script src="#Url.Content("~/Scripts/bootstrap.min.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-1.9.0.min.js")"></script>
<script src="#Url.Content("~/Scripts/gridmvc.min.js")"></script>
<title>Index</title>
</head>
<body>
<div class="container">
</div>
<div class="container">
#helper RenderDeleteForm(HREmployee hremp)
{
<form method="POST" action="#Url.Action("Delete", "HR201", new { EmpID = hremp.EmpID })">
<button type="submit" class="modal-link" onclick="return confirm('Are you sure you want to delete employee: #hremp.LastNm?');">
Delete
</button>
</form>
}
<h2>HR201</h2>
<div class="pull-left">
#using (Html.BeginForm())
{
<button type="submit" class="btn btn-primary">Add</button>
<button type="submit" class="modal-link">MODAL</button>
}
</div>
#Html.Grid(Model).Columns(columns =>
{
columns.Add(c => c.EmpID).Titled("EmpID").Filterable(true);
columns.Add(c => c.FirstNm).Titled("First Name");
//columns.Add(c => c.MiddleNm).Titled("Middle Name");
//columns.Add(c => c.LastNm).Titled("Lastn Name");
columns.Add(c => c.BirthDt).Titled("BirthDay").Format("{0:dd MMM yyyy}").Filterable(true);
columns.Add().Titled("Action")
.Sanitized(false)
.Encoded(false)
.RenderValueAs(d => Html.ActionLink("Edit", "Edit", new { EmpID = d.EmpID }, new { #class = "modal-link" }));
columns.Add().Titled("Action2")
.Sanitized(false)
.Encoded(false)
.RenderValueAs(c => RenderDeleteForm(c));
}).WithPaging(10).Sortable(true)
#Html.ActionLink("Click to Add Customer", "Edit",new{EmpID = "E9770003"}, new { #class = "modal-link" })
</div>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">Ă—</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>Loading…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
<script>
//this script reset modal each time when you click on the link:
$(function () {
$(".modal-link").click(function (event) {
event.preventDefault();
$('#myModal').removeData("modal");
$('#myModal').modal({ remote: $(this).attr("href") });
});
})
</script>
</body>
</html>
EDIT VIEW
<div class="container">
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<fieldset>
<legend>HREmployee</legend>
<div class="editor-label">
#Html.LabelFor(model => model.EmpID)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.EmpID)
#Html.ValidationMessageFor(model => model.EmpID)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.FirstNm)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.FirstNm)
#Html.ValidationMessageFor(model => model.FirstNm)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.LastNm)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.LastNm)
#Html.ValidationMessageFor(model => model.LastNm)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.MiddleNm)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.MiddleNm)
#Html.ValidationMessageFor(model => model.MiddleNm)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.SenseID)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.SenseID)
#Html.ValidationMessageFor(model => model.SenseID)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.NickNm)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.NickNm)
#Html.ValidationMessageFor(model => model.NickNm)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.BirthDt)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.BirthDt)
#Html.ValidationMessageFor(model => model.BirthDt)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
</div>
**

MVC4 retrieve uploaded files

I'm using ASP.NET MVC4 in order to develop an intranet application. One of the main features is to allow the user to upload files which will be stored in my database. In order to do that, I'm using jQuery. However, I have no idea what I have to do to manipulate the uploaded files. I already know that I have to manipulate them into the correspondent controller but after having read some tips on the internet, I just can't see how I am suppose to do.
Here is my view :
#model BuSIMaterial.Models.ProductAllocationLog
#{
ViewBag.Title = "Create";
}
<h2>Create</h2>
#using (Html.BeginForm())
{
#Html.ValidationSummary(true)
<fieldset>
<legend>ProductAllocationLog</legend>
<div class="editor-label">
Date :
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.Date, new { #class = "datepicker"})
#Html.ValidationMessageFor(model => model.Date)
</div>
<div class="editor-label">
Message :
</div>
<div class="editor-field">
#Html.TextAreaFor(model => model.Message)
#Html.ValidationMessageFor(model => model.Message)
</div>
<div class="editor-label">
Allocation :
</div>
<div class="editor-field">
#Html.DropDownList("Id_ProductAllocation", String.Empty)
#Html.ValidationMessageFor(model => model.Id_ProductAllocation)
</div>
<div class="demo" style="float:left; margin-top:5px;">
<div id="aupload" style = "border:2px dashed #ddd; width:100px; height:100px; margin-right:10px; padding:10px; float:left;"></div>
<div id="uploaded" style = "border: 1px solid #ddd; width:550px; height:102px; padding:10px; float:left; overflow-y:auto;"></div>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
I'm absolutly not asking for pre-made code samples but just for a way to proceed. It would be very kind.
There are three things you need to do. First, add an image upload field to your view:
<input type="file" name="file-upload" />
..make your form 'multipart'..
#using (Html.BeginForm("Action", "Controller", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
}
...then in your controller, access the file via the 'Files' collection on the request object:
Request.Files["file-upload"];
If you wish to submit the form with ajax/jquery, then there is a little more work to do to serialize the files. This post will help you with this: Sending multipart/formdata with jQuery.ajax
#model MVCDemo.Models.tbl_Images
#{
ViewBag.Title = "Create";
}
<h2>Create</h2>
#using (Html.BeginForm())
{
#Html.ValidationSummary(true)
<fieldset>
<legend>ProductAllocationLog</legend>
<div class="editor-label">
Date :
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.Date, new { #class = "datepicker"})
#Html.ValidationMessageFor(model => model.Date)
</div>
<div class="editor-label">
Message :
</div>
<div class="editor-field">
#Html.TextAreaFor(model => model.Message)
#Html.ValidationMessageFor(model => model.Message)
</div>
<div class="editor-label">
Allocation :
</div>
<div class="editor-field">
#Html.DropDownList("Id_ProductAllocation", String.Empty)
#Html.ValidationMessageFor(model => model.Id_ProductAllocation)
</div>
<div class="demo" style="float:left; margin-top:5px;">
<div id="aupload" style = "border:2px dashed #ddd; width:100px; height:100px; margin-right:10px; padding:10px; float:left;"></div>
<div id="uploaded" style = "border: 1px solid #ddd; width:550px; height:102px; padding:10px; float:left; overflow-y:auto;"></div>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>

Categories

Resources