unable to pass parameter value inside Html.EditableGridView in mvc cshtml - asp.net-mvc

In MVC 4 project I tried to pass parameter value like following but I failed due to syntax.
In .cshtml file
#(Html.EditableGridView<MyModel>("TestGridView",Model,Server.MapPath("~/XmlFile/Test.xml"),GridRowSelectionMode.Multiple,
new { cssObj = "genericContentCss", url = "/Test/GetMyPartial?mode=Edit&id=" }))
in url want to pass id parameter value like id=#Model.Id
but it is not working I'm missing something very small , I tried google but failed to do this can anyone give me clue
thanks

How about this:
#Html.EditableGridView<MyModel>("TestGridView",
Model,
Server.MapPath("~/XmlFile/Test.xml"),
GridRowSelectionMode.Multiple,
new { cssObj = "genericContentCss",
url = "/Test/GetMyPartial?mode=Edit&id="+Model.Id
}
)
or you can use Url.Action():
url = Url.Action("GetMyPartial","Test",new { mode="Edit" , id=Model.Id })
in above code:
#Html.EditableGridView<MyModel>("TestGridView",
Model,
Server.MapPath("~/XmlFile/Test.xml"),
GridRowSelectionMode.Multiple,
new { cssObj = "genericContentCss",
url = Url.Action("GetMyPartial","Test",new { mode="Edit" , id=Model.Id })
}
)

Related

Still having ddl redirect issues

I am still having issues. I think what I am trying to do is simple. I have a viewbag droplist - which is working fine. I just want to redirect on selection it redirect just like: #Html.ActionLink("Branch", "Employees", new { Branch = item.Branch }) | (but with the selection from the droplist) Should this be difficult?
#Html.DropDownList("Branches", ViewBag.Branches as SelectList, "Select a Branch", new { #id = "ddlBranch" })
<script>
$(function () {
$("#ddlBranch").on("change", function () {
var deptId = $(this).val();
var routeVal = { Id: deptId };
var url = '#Url.Action("Department", "Home")';
$.ajax({
url: url,
type: 'POST',
data: routeVal
}).done(function (result) {
window.location.href = result.newUrl;
})
})
})
</script>
From a comment on the question above:
So now I just need to redirect to: #Html.ActionLink("Branch", "Employees", new { Branch = item.Branch }) but Item.Branch would be $(this).val(). Can this be done?
There may be a more elegant way, but an approach I've always taken is something like this:
let url = '#Html.ActionLink("Branch", "Employees", new { Branch = "REPLACEME" })';
url = url.replace('REPLACEME', $(this).val());
window.location.href = url;
On the client-side this turns into something like:
let url = '/Brand/Employees?Branch=REPLACEME';
url = url.replace('REPLACEME', encodeURIComponent($(this).val()));
window.location.href = url;
Which would look silly to anybody examining only the client-side code, I'm sure. But since the Branch parameter might be in the query string or might be in the route, and since it's the ASP.NET MVC Framework's responsibility to manage that, generating the URL and putting the client-side value into the URL are two separate responsibilities here.
So we use the server-side code to generate the URL with a placeholder (can be any string, "REPLACEME" was an arbitrary choice) and then use the client-side code to dynamically replace that placeholder with the desired value.
This essentially replaces whatever you're trying to do with AJAX in the original question. Unless you need to invoke a server-side operation to get a result not known to the client-side code in order to build the URL, you can just omit the AJAX entirely and build the URL directly.

Angular 7 & ionic 4 Router - Pass the method

I am implmenting the angular router in the hybrid mobile application.(Upgrading from ionic 3 to 4). One my scnerio, I want to pass the method as a query parameter to another page. For example, Call the page "studentEditPage" from "Student Detail Page" and passing the "Update" method name to student edit page. Before poping the "StudentEditPage", it calls the update method then pop. I am tring to pass the method in the queryparam in navigate but it does not accept it in ionic 4. Are we able to pass the method as a param in the queryparameters
From StudentDetailPage
let navigationExtras : NavigationExtras = {
state : {
param : { detail: "editcategory", value: studentName, callback: this.updateStudentCallback, }
}
}
that.router.navigate(['studentDetailsPage'],navigationExtras); Here "this.updateStudentCallback" as a method.
From StudentEditPage:
this.updateStudentCallback(tempEmpData).then(() => {
this.navigate.router(['studentEditPage'])
});
I have googled and searched the angular posts but unable to get the proper results. THanks in Advance.
Well you can id like this:
where you want send/pass id/param put id here on the app-routing.module.ts file
{ path: 'studentedit/:sid', loadChildren: './studentedit/studentedit.module#StudentEditPageModule'},
then in html file
<h1 (click)="gotoUpdate(std.studentID)" >click</h1>
in ts file
gotoProductlist(studentID: string) {
this.navCtrl.navigateForward('/studentUpdate/' + studentID);
}
in Edit Page
ngOnInit() {
// Get the ID that was passed with the URL
let id = this.activatedroute.snapshot.paramMap.get('sid');
}
Well you can get id from another page.

How to modify an URL in a view in CakePHP 2.x

It seems quite simple but there is something I am not able to figure out. I hope someone can help me fast.
I have an url, something like http://host/controller/action/argument/named:1/?query1=1. I want to add another query param to look it like http://host/controller/action/argument1/argument2/named:1/?query1=1&query2=2. I fact I want to add query2=2 to all URLs on a particular page, through some callback or something.
An URL may or may not have query params in the existing page URL.
How do I do it?
Example url : http://www.example.com/myController/myAction/param1:val1/param2:val2
You can use :
$this->redirect(array("controller" => "myController",
"action" => "myAction",
"param1" => "val1",
"param2" => "val2",
$data_can_be_passed_here),
$status,
$exit);
Hope it helps you.
May be I am thinking too much of it but here is how it came out. I put it in a UtilityHelper.
function urlmodify($params = array(), $baseurl = true) {
$top_level_1 = array('plugin', 'controller', 'action'); //top level vars
$top_level_2 = array('pass', 'named'); //top level vars
//for integrated use
$top_level = array_merge($top_level_1, $top_level_2);
$urlparams = array();
//get top level vars
foreach($top_level as $k) {
if(in_array($k, $top_level_1)) {
$urlparams[$k] = $this->request->params[$k];
}
if(in_array($k, $top_level_2)) {
$$k = $this->request->params[$k]; //create $pass & $named
}
}
//get query vars
if($this->request->query) {
$urlparams['?'] = $this->request->query;
}
//check for custom pass vars
if(isset($params['pass'])) {
$pass = array_merge($pass, $params['pass']);
}
//pass var has to be in numarical index
foreach($pass as $v) {
array_push($urlparams, $v);
}
//check for custom named vars
if(isset($params['named'])) {
$named = array_merge($named, $params['named']);
}
//pass var has to be in key=>value pair
foreach($named as $k=>$v) {
$urlparams[$k] = $v;
}
//check for custom query vars
if(isset($params['?'])) {
$urlparams['?'] = array_merge($urlparams['?'], $params['?']);
}
return Router::url($urlparams, $baseurl);
}
}
I have an URL: http://localhost/project/exlplugin/logs/manage_columns/1/a:1/n:1/?b=1. On some links I want to add some certain parameters. Here is the result when i call
echo $this->Utility->urlmodify(array('pass'=>array(2), 'named'=>array('m'=>2), '?'=>array('c'=>2)));*
It gives: http://localhost/thecontrolist/spreadsheet/logs/manage_columns/1/2/a:1/n:1/m:2?b=1&c=2
I just wanted to add just a query parameter to all my listing urls deleted=0 or deleted=1 for the SoftDelete thing :)
Thank you #u2460470 for the answer but it's just about modifying (not removing or creating anything but just adding some params to) current URL on a view page.

How to create ODataNavigationLink when using ODataLib entry writer?

I am trying to find an example of how to properly instantiate ODataNavigationLink in case it's non-empty. The only code example I've found creates a non-expanded link but doesn't bind it to any data:
//create a non-expanded link for the orders navigation property
writer.WriteStart(new ODataNavigationLink()
{
IsCollection = true,
Name = "Orders",
Url = new Uri("http://microsoft.com/Customer(" +
dataSource.Customers.First().CustomerID + ")/Orders")
});
writer.WriteEnd(); //ends the orders link
So here we specify the link to "Orders". But how do I provide the actual values for the link (in this example the link is a collection but it can also be a single entry). When I was writing the payload manually I was providing "href" attribute with a linked entry ID. I can't figure out how this is done with ODataLib.
The value appear in the 'href' attribute just shows the Url property of ODataNavigationLink, so you can try the following code to set it manually:
//create a non-expanded link for the orders navigation property
writer.WriteStart(new ODataNavigationLink() {
IsCollection = true,
Name = "Orders",
Url = new Uri("http://microsoft.com/Orders(3)") });
writer.WriteEnd(); //ends the orders link
In common, the navigation link should be the source entity url followed by the navigation property,see here, while id should point to the real entry ID.
updated:
According to the latest feedback, you're trying to write the 'Collection of links' as described in section 14.1 of the atom spec. Thus you can try ODataEntityReferenceLinks class:
var referenceLink1 = new ODataEntityReferenceLink { Url = new Uri("http://host/Orders(1)") };
var referenceLink2 = new ODataEntityReferenceLink { Url = new Uri("http://host/Orders(2)") };
var referenceLink3 = new ODataEntityReferenceLink { Url = new Uri("http://host/Orders(3)") };
var referenceLinks = new ODataEntityReferenceLinks
{
Links = new[] { referenceLink1, referenceLink2, referenceLink3 }
};
writer.WriteEntityReferenceLinks(referenceLinks);
and the payload would be something like:
<links xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
<uri>http://host/Orders(1)</uri>
<uri>http://host/Orders(2)</uri>
<uri>http://host/Orders(3)</uri>
</links>

Url.Action is throwing error CS1026: ) expected

This is hopefully just a syntax error as I'm new to MVC and trying to edit something that already exists without having much experience. Having spent ages trying different syntax I'm obviously missing something.
My issue is that I have this:
var url = '<%= Url.Action("List") %>?page=' + pageNo;
which is fine, but its not passing in all the required parameters as part of pager functionality.
What I want to use is something like:
var url = '<%= Html.RenderAction("List",
"PlacementAgreementAgencyPlacementAgreementsPlacement",
new { Domain = "Placement",
Id = Model.Item.PlacementAgreement.PlacementAgreementId,
agencyPlacementAgreementId = Model.Item.AgencyPlacementAgreementId,
Page = Model.PageNo
});
%>';
But it always complains about error CS1026: ) expected
Same with trying
<%= Url.Action("List", "PlacementAgreementAgencyPlacementAgreementsPlacement",
new { Domain = "Placement",
Id = ViewData.Model.AgencyPlacementAgreement.PlacementAgreement.PlacementAgreementId,
agencyPlacementAgreementId = ViewData.Model.AgencyPlacementAgreement.AgencyPlacementAgreementId,
Page = Model.PageNo }
)%>
If someone could point out what I'm doing wrong that would be great. Basically I'm trying to call controller PlacementAgreementAgencyPlacementAgreementsPlacement with action List passing in all parameters Id, agencyPlacementAgreementId and Page. It's being done in javascript so that I can use this:
function loadAgreementPlacementPage(pageNo) {
var url = '<%= Url.Action("List") %>?page=' + pageNo;
$.get(url, function(data) {
$("#agreementplacement_list_holder").html(data);
});
Thanks!!!
PS. Using MVC 1.0.
It should be:
var url = '<%= Url.Action(
"List",
"PlacementAgreementAgencyPlacementAgreementsPlacement",
new {
Domain = "Placement",
Id = Model.Item.PlacementAgreement.PlacementAgreementId,
agencyPlacementAgreementId = Model.Item.AgencyPlacementAgreementId,
Page = Model.PageNo
}) %>';
Use Url.Action instead of Html.RenderAction and remove the semicolon at the end.
Remove the semicolon before the closing tag

Resources