I have a problem. My Problem is I can not pass parameters from RootPageMenuItem to Constructer of Content Page.
my code:
new RootPageMenuItem { Id = 4, Title = "myTitle", ImageSource = "rightArrow.png", TargetType = typeof(myContentPage) },
I want to achieve this:
new RootPageMenuItem { Id = 4, Title = "myTitle", ImageSource = "rightArrow.png", TargetType = typeof(myContentPage(_param1,_param2)) },
How can i do this?
Solution:
if(item.TargetType == typeof(myContentPage))
{
//This will create instance of the page using the parameterized constructor you defined in each DetailPages
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType, param1 ,param2));
}
else
{
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
}
Here is a similar issue which you can refer .
Related
Using web.ensureuser, may I know is there a way to still retrieve the SPUser object when the user does not exist in the AD anymore?
Or can I recreate the SPUser object?
foreach (var requestUser in requestUsers)
{
var item = requestUserList.Items.Add();
bool allowUnsafeUpdate = web.AllowUnsafeUpdates;
try
{
if (!allowUnsafeUpdate)
{
web.AllowUnsafeUpdates = true;
}
requestUser.User = web.EnsureUser(requestUser.LoginId); <---dead here
web.AllowUnsafeUpdates = allowUnsafeUpdate;
finally
{
web.AllowUnsafeUpdates = allowUnsafeUpdate;
}
var userProfile = UserProfile.GetUserProfile(requestUser.User);
item[OUASSharedMailboxRequestUserInternalName.RequestId] = requestIdLookup;
item[OUASSharedMailboxRequestUserInternalName.User] = requestUser.User;
item[OUASSharedMailboxRequestUserInternalName.PermissionType] = requestUser.PermissionType;
item[OUASSharedMailboxRequestUserInternalName.EmployeeId] = new SPFieldLookupValue(userProfile.ID, userProfile.EmployeeId);
item[OUASSharedMailboxRequestUserInternalName.LoginId] = requestUser.LoginId;
item[OUASSharedMailboxRequestUserInternalName.Action] = requestUser.Action;
item[OUASSharedMailboxRequestUserInternalName.Status] = requestUser.Status;
web.AllowUnsafeUpdates = true;
item.Update();
web.AllowUnsafeUpdates = false;
}
UPDATE: I was suggested to use the following:
requestUser.User = web.EnsureUser[requestUser.LoginId];
There are still some errors during the validations, and I'm currently resolving them.
Q: Are there any workarounds if the user does not exist in the AD as well as the SP List?
Use the following line of code to get the site user.
SPUser user = web.AllUsers.Cast<SPUser>().FirstOrDefault(u => u.LoginName.Contains("domain\\username"));
I am writing ASP.NET Custom Component, I want to update my view with following code below:
#if (Model.TableDatasource != null){
//Write some thing to html page example: tables or span
}
At the first, Model.TableDatasource is null, user choose information and Controller Review View(Model) like this:
var model = new PrintDeliveryTicketModel()
{
PlantList = CommonHelper.GetPlantList(),
};
if (request == null)
{
return View(model);
}
else
{
var currentPlant = JsonConvert.DeserializeObject<PlantList>(request);
var FullModel = new PrintDeliveryTicketModel()
{
PlantList = CommonHelper.GetPlantList(),
CurrentPlant = JsonConvert.DeserializeObject<PlantList>(request),
DriverList = JsonConvert.DeserializeObject<List<Drivers>>(CommonHelper.GetDriver(currentPlant.CodePlant, currentPlant.PlantNo.Value).Content.ReadAsStringAsync().Result),
CustomerList = JsonConvert.DeserializeObject<List<Customer>>(CommonHelper.GetCustomer().Content.ReadAsStringAsync().Result),
RecipeList = JsonConvert.DeserializeObject<List<Recipe>>(CommonHelper.GetRecipe(currentPlant.CodePlant, currentPlant.PlantNo.Value).Content.ReadAsStringAsync().Result),
SitesList = JsonConvert.DeserializeObject<List<Site>>(CommonHelper.GetSite().Content.ReadAsStringAsync().Result),
// TruckList = JsonConvert.DeserializeObject<List<Truck>>(CommonHelper.GetTruck().Content.ReadAsStringAsync().Result)
};
return View(FullModel);
}
At the Debug time, I notice that break-point stop at return View(FullMode) and Break-point at ViewFile(cshtml) has value. but nothing printed at view.
Hope some help.
Our asp.net application uses EXT.NET.
When a "View" menu is clicked, an EXT.NET window shows up with a content of a PDF file.
The problem is we can't drag and drop that window to a body of an Outlook email (to make it as the email attachment).
I am thinking one of the way to drag and drop to a body of an Outlook email is to show the PDF file in the browser window, not an EXT.NET window. How can I do that ?
Thank you.
This is from the View (Index.cshtml):
#{
ViewBag.Title = "Archive";
var X = Html.X();
}
#section SPAViews {
#(
X.Viewport().Layout(LayoutType.Fit).Items(
X.TabPanel().ID("ArchiveTabPanel")
.Items(
X.GridPanel().ID("GridPanel1").MarginSpec("1 1 1 1").Cls("cust-grid").Title("Archive").Icon(Icon.ServerCompressed)
.Plugins(X.GridFilters())
.View(Html.X().GridView().StripeRows(true).TrackOver(false))
.SelectionModel(X.CheckboxSelectionModel().Mode(SelectionMode.Multi))
.TopBar(
X.Toolbar().MinHeight(35)
.Items(
:
, X.Button()
.Text("View")
.Icon(Icon.PageWhiteAcrobat)
.DirectEvents(de =>
{
de.Click.Action = "Submit";
de.Click.EventMask.ShowMask = true;
de.Click.Method = HttpMethod.POST;
de.Click.ExtraParams.Add(new Parameter()
{
Name = "selection",
Value = "getselection()",
Mode = ParameterMode.Raw
});
de.Click.Timeout = 360000;
})
This is from ArchiveController.cs:
public ActionResult Submit(string selection)
{
int cnt = SetTempData(selection);
RenderWindows(String.Format("View Archive {0}.",cnt),0,cnt);
return this.Direct();
}
[ChildActionOnly]
public void RenderWindows(string title,int download,int cnt)
{
Window win = new Window
{
ID = "Windows1",
Title = title,
Icon = Ext.Net.Icon.PageWhiteAcrobat,
Height = download == 1 ? 150 : 600,
Width = download == 1 ? 400 : 800,
BodyPadding = 2,
Modal = true,
Layout = "Fit",
CloseAction = CloseAction.Destroy,
Loader = new ComponentLoader()
{
Url = Url.Action("ArcTicket", "Archive"),
Mode = LoadMode.Frame,
DisableCaching = true,
ShowWarningOnFailure = true,
LoadMask = { ShowMask = true, Msg = String.Format("Generating {0} pdf ...",cnt) }
},
Buttons = {
new Button(){ Text="Close & Clear", Icon=Ext.Net.Icon.TableRowDelete, Handler="App.GridPanel1.selModel.deselectAll();App.Windows1.close();"},
new Button(){ Text="Close", Icon=Ext.Net.Icon.Cancel, Handler="App.Windows1.close();"}
}
};
win.Loader.Params.Add(new Parameter() { Name = "download", Value = download.ToString(), Mode = ParameterMode.Value });
win.Render(RenderMode.Auto);
}
public FileStreamResult ArcTicket(int download)
{
String id = TempData["xid"].ToString();
TempData.Remove("xid");
String ticket = Uow.TICKETs.GetXmlBatch(id);
Byte[] pdf = MvcApplication.Fop.Write(enumFobFormat.Pdf
, ticket
, Server.MapPath("/Resources/xslt/Ticket.xsl")
);
MemoryStream ms = new MemoryStream(pdf);
FileStreamResult fs = new FileStreamResult(ms, "application/pdf");
if (download == 1)
fs.FileDownloadName = string.Format("Archive_{0:yyyyMMdd_HHmmss}.pdf", DateTime.Now);
return fs;
}
You can make normal button / link with href to ArcTicket action with target="_blank" then it will be opened in new tab
Update:
Change .TopBar to something like this. Option 1 may be problematic because of dynamic parameter from grid and i am not sure it will be possible to pass it there
Option 1:
.TopBar(
X.Toolbar().MinHeight(35)
.Items(
:
, X.Button()
.Text("View")
.Icon(Icon.PageWhiteAcrobat)
.Href(Url.Action("ArcTicket", "Archive"))
.HrefTarget("blank")
.BaseParams("yourparameters")
Option 2
.TopBar(
X.Toolbar().MinHeight(35)
.Items(
:
, X.Button()
.Text("View")
.Icon(Icon.PageWhiteAcrobat)
.Handler("YourJSFUnctionWithWIndowOpen")
I am using ASP.NET MVC 6 Web API. In the View I use free-jqgrid.
Let's borrow Oleg's free jqgrid data to demonstrate my purpose. We already have the table shown.
Next I am going to add new Vendor. Please notify that there is primary key id(identity column) in the database. We don't want it displaying in the screen.
In VendorRespository.cs, I add the new Vendor as
public void AddVendor(Vendor item)
{
using (VendorDataContext dataContext = new VendorDataContext())
{
dataContext.Database.Connection.ConnectionString = DBUtility.GetSharedConnectionString(
"http://centralized.admin.test.com");
var newVendor = dataContext.Vendors.Create();
newVendor.Company = item.Company;
newVendor.ContactName = item.ContactName;
newVendor.ContactPhone = item.ContactName;
newVendor.UserName = item.UserName;
newVendor.UserKey = item.UserKey;
newVendor.Active = item.Active;
newVendor.FacilityId =item.FacilityId;
newVendor.ClientID = item.ClientID;
dataContext.SaveChanges();
}
}
My questions:
Not sure the script like?
<script>
API_URL = "/VendorManagement/";
function updateDialog(action) {
return {
url: API_URL
, closeAfterAdd: true
, closeAfterEdit: true
, afterShowForm: function (formId) { }
, modal: true
, onclickSubmit: function (params) {
var list = $("#jqgrid");
var selectedRow = list.getGridParam("selrow");
rowData = list.getRowData(selectedRow);
params.url += rowData.Id;
params.mtype = action;
}
, width: "300"
};
}
jQuery("#jqgrid").jqGrid('navGrid',
{ add: true, edit: true, del: true },
updateDialog('PUT'),
updateDialog('POST'),
updateDialog('DELETE')
);
In the controller, not sure what is the code?
// POST
public HttpResponseMessage PostVendor(Vendor item)
{
_vendorRespository.AddVendor(item);
var response = Request.CreateResponse<Vendor>(HttpStatusCode.Created, item);
string uri = Url.Link("DefaultApi", new { id = item.Id });
response.Headers.Location = new Uri(uri);
return response;
}
My code has many compiling errors such as
'HttpRequest' does not contain a definition for 'CreateResponse' and the best extension method overload 'HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage, HttpStatusCode, Vendor)' requires a receiver of type 'HttpRequestMessage'
Please help me to get rid of the error and inappropriate code.
EDIT:
I borrowed the code snippet from here.
I need add the code such as
[Microsoft.AspNet.Mvc.HttpGet]
public dynamic GetVendorById(int pkey)
{
return null;
}
And
// POST
[System.Web.Http.HttpPost]
public HttpResponseMessage PostVendor(Vendor item)
{
_vendorRespository.AddVendor(item);
var response = Request.CreateResponse<Vendor>(HttpStatusCode.Created, item);
string uri = Url.Link("/VendorManagement/GetVendorById", new { id = item.pkey });
response.Headers.Location = new Uri(uri);
return response;
}
I just made a form containing a DropDownList, it perfectly shows the option names, but doesn't post the ID of the selected option into the controller.
Here is the code for the controller:
[HttpGet]
public ActionResult Insert(int id)
{
TemplateRepository repo = new TemplateRepository();
List<Template> templateList = repo.ListAll().ToList<Template>();
ViewData["Template"] = new SelectList(templateList, "Id", "Omschrijving");
return View();
}
[HttpPost]
public ActionResult InsertOrEditSubmit(Klant klant)
{
KlantRepository repo = new KlantRepository();
klant.Naam = Request["Naam"];
klant.Adres = Request["Adres"];
klant.Postcode = Request["Postcode"];
klant.Woonplaats = Request["Woonplaats"];
klant.Email = Request["Email"];
klant.Telefoon = Request["Telefoon"];
repo.SaveOrUpdate(klant);
return RedirectToAction("Index");
}
And here is the code in the view:
#using (Html.BeginForm("InsertOrEditSubmit", "Klant", FormMethod.Post))
{
#Html.DevExpress().Label(
settings =>
{
settings.ControlStyle.CssClass = "label";
settings.Text = "Template";
settings.AssociatedControlName = "Template";
}
).GetHtml() <br />
#Html.DropDownList("Template", ViewData["Template"] as SelectList);
#Html.DevExpress().Button(
settings =>
{
settings.ControlStyle.CssClass = "button";
settings.Name = "Insert";
settings.Text = "Toevoegen";
settings.UseSubmitBehavior = true;
}
).GetHtml()
#Html.DevExpress().Button(
settings =>
{
settings.ControlStyle.CssClass = "button";
settings.Name = "Cancel";
settings.Text = "Terug";
settings.ClientSideEvents.Click = "function(s, e){ document.location='" + DevExpressHelper.GetUrl(new { Controller = "Gebruiker", Action = "Index" }) + "'; }";
}
).GetHtml()
}
Hope someone can explain why it doesn't post the ID..
Try: Request["Template"];
Try a simple test:
(Controller)
ViewData["Test"] = new SelectList(new[] {new {Id = 1, Text = "Test 1"}, new {Id = 2, Text = "Test 2"}, new {Id = 3, Text = "Test 3"}}, "Id", "Text");
(View)
#Html.DropDownList("Test", ViewData["Test"] as SelectList)
Now the Request["Test"] should return the Id of the selected value.
But if your View is strongly-typed, in your case to the object "Klant", you don't need to fill the values with the Request, the object will be auto-populated and if your object have a property Template it'll be populated too.
I have found that sometimes having a name along with the id for an input solves this issue.
What does your rendered html for the Template control look like?