The view 'ProductTemplate.Simple' or its master was not found or no view engine supports the searched locations - nopcommerce

actually i want to insert product and its count in new table when click on product using plugin. I have done this without plugin.
i copied product action method in my plugin but problem is that first call nop.web.catalog controller 's product action method then called my plugin 's product action method when wrote
#Html.Action("Product", "ProductMostviewed", new { productId = Model.Id }) in ProductTemplate.simple.cshtml
but problem is occur on #Html.Action("Product", "ProductMostviewed", new { productId = Model.Id }) in ProductTemplate.simple.cshtm .error is " The view 'ProductTemplate.Simple' or its master was not found or no view engine supports the searched locations. "
please help.
Thank You in advance.

I've seen two different things cause this error.
This can happen if you haven't set view to be an "Embedded Resource".
This can happen if you did not reference the view properly in the Controller action. It should be something like:
//This is right
return View("Nop.Plugin.<namespace>.<pluginname>.Views.<ControllerName>.<ViewName>", model);
//This is wrong
return View(model);

Related

Relational Query - 2 degrees away

I have three models:
Timesheets
Employee
Manager
I am looking for all timesheets that need to be approved by a manager (many timesheets per employee, one manager per employee).
I have tried creating datasources and prefetching both Employee and Employee.Manager, but I so far no success as of yet.
Is there a trick to this? Do I need to load the query and then do another load? Or create an intermediary datasource that holds both the Timesheet and Employee data or something else?
You can do it by applying a query filter to the datasource onDataLoad event or another event. For example, you could bind the value of a dropdown with Managers to:
#datasource.query.filters.Employee.Manager._equals
- assuming that the datasource of the widget is set to Timesheets.
If you are linking to the page from another page, you could also call a script instead of using a preset action. On the link click, invoke the script below, passing it the desired manager object from the linking page.
function loadPageTimesheets(manager){
app.showPage(app.pages.Timesheets);
app.pages.Timesheets.datasource.query.filters.Employee.Manager._equals = manager;
app.pages.Timesheets.datasource.load();
}
I would recommend to redesign your app a little bit to use full power of App Maker. You can go with Directory Model (Manager -> Employees) plus one table with data (Timesheets). In this case your timesheets query can look similar to this:
// Server side script
function getTimesheets(query) {
var managerEmail = query.parameters.ManagerEmail;
var dirQuery = app.models.Directory.newQuery();
dirQuery.filters.PrimaryEmail._equals = managerEmail;
dirQuery.prefetch.DirectReports._add();
var people = dirQuery.run();
if (people.length === 0) {
return [];
}
var manager = people[0];
// Subordinates lookup can look fancier if you need recursively
// include everybody down the hierarchy chart. In this case
// it also will make sense to update prefetch above to include
// reports of reports of reports...
var subortinatesEmails = manager.DirectReports.map(function(employee) {
return employee.PrimaryEmail;
});
var tsQuery = app.models.Timesheet.newQuery();
tsQuery.filters.EmployeeEmail._in = subortinatesEmails;
return tsQuery.run();
}

How to get an id from url and use it in another controller create view

I'm very new to .net C# but I wound to get the id I put in the url. In my project details I put a link to create member. but now the users have to select that previous project Id with an combo box. I wound this to be auto.
In my project/details
#Html.ActionLink("Add member", "Create", "ProjectMember", new { id=Model.ProjectID }, null)
Result =>
ProjectMember/Create/1 (=id from project)
I want to get the ID so wen I create a new projectmember the user does not have to select the id from project from the dropbox that was auto generated in the create view
I looked some things up and came with this answer
<%=Url.RequestContext.RouteData.Values["id"]%>
but when i post this in the It came out the view exactly like <%=Url.RequestContext.RouteData.Values["id"]%>
you can pass id in ActionLink Like this
#Html.ActionLink("Add member", "Create", "ProjectMember", new { id=Model.ProjectID }, null)
for more information . see this link ActionLink

ASP.NET MVC 3 - #Html.DropDownList - How do I change the description?

The following code in a cshtml file creates a dropdown with a list of Contacts, but the field it uses for the description of values, is not the one I want to display.
How do I force it to choose data from a different field in the Contact object?
#Html.DropDownList("ContactId", String.Empty)
#Html.DropDownListFor(a => a.OtherContactId,
new SelectList(Model.ContactList, "ContactId", "ContactValue",
Model.OtherContactId), "-- Select --")
where, Model.ContactList is populated in your controller action.
p.s. I'm not entirely certain whether you mean change the title of the select option text or the property that is updated, so have presented a kind of hybrid offering
You can try something like this on the server side(controller):
ViewBag.ContactList = new SelectList(iContactRepository.GetAllContacts(),
"ContactId", "Name", contactDefault.ContactId);
//Here the method GetAllContacts returns Iqueryable<Contact>.
And this on the view:
#Html.DropDownList("ContactIdSelect", ViewBag.ContactList as SelectList)
This is the SelectList documentation.
Hope it helps.

TemplateInfo into Controller

how can i get a form field id after submitting the form. im trying like this:
ViewData.TemplateInfo.GetFullHtmlFieldId(logOnParts.Part.UserNameOrEmail)
but no work on controller side. i need to get "Part_UserNameOrEmail" something..
if (String.IsNullOrEmpty(logOnParts.Part.UserNameOrEmail))
{
ModelState.AddModelError("Part_UserNameOrEmail", "error");
TempData["logon-focus-field"] = "Part_UserNameOrEmail";
}
so i will focus the field on view side like this:
$(document).ready(function () {
$('#TempData["logon-focus-field"]').focus();
});
A controller should absolutely not need such information. The generated id is a view specific information. If you need this in a controller this simply means that you have some serious design problem with your application. Unfortunately as you haven't explained your scenario in the question it is difficult to help you solving this problem. So in your controller you could do this:
Expression<Func<MyViewModel, string>> expression = x => x.Part.UserNameOrEmail;
string name = ExpressionHelper.GetExpressionText(expression);
string id = new TemplateInfo().GetFullHtmlFieldId(name);

MVC3 Razor Dynamic creating forms

First I want to point out Im very new to this area ^_^ .
Anyhow
I'm doing a project with a grade-reporting system and now Im currently working with the cshtml for the update of usertask.
My problem is
I'm currently working with trying to add a form post but it's not really working at all.
To my view I have a model with a list of usertasks (and other data). These usertasks contains int id and string grade.
What I am trying to do is foreach usertask create a form with their own submit button.
The form would have a hidden field for id and a textbox for grading.
The problem i have with #Html.Hidden
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Hidden' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Which I assume is you cant dynamicaly use Html.Hidden (i use a foreach loop over the list of usertasks).
Anyone have any idea how to solve this? I've been thinking about creating partialviews but couldnt figure out if you could pass paramters to them. Or make the submit button redirect to a controller-view which takes the 2 paramters?
Anyone have any examples?
Thx for help!
Submitting some code I have been trying to get to work.
foreach (var tskModel in tskgrpModel.usertasks)
{
#tskModel.name
using (Html.BeginForm("Update", "Teacher", FormMethod.Post))
{
if(tskModel.isSet == true)
{
#Html.Hidden("ut_id", tskModel.id )
#Html.TextBox("ut_grade",(string)#tskModel.grading);
}
else
{
#Html.Hidden("ut_id", -1)
#Html.Hidden("ut_id", "NotSet")
}
}
}
Is taskModel.id a dynamic variable?
if so change the line
#Html.Hidden("ut_id", tskModel.id )
to
#Html.Hidden("ut_id", (int) tskModel.id )

Resources