access to article by article name in ASP.NET MVC2 - asp.net-mvc-2

Greetings. How can I make access to my article or post by their name?
For example: Like at stackoverflow has access to this question by the name
access to article by article name in ASP.NET MVC2access-to-article-by-article-name-in-asp-net-mvc2

On StackOverflow the name part is completely ignored. It's the id that is important. This works: access to article by article name in ASP.NET MVC2 and links to this question. To generate links that contain the name in the URL you could define the following route:
routes.MapRoute(
"NameIdRoute",
"{controller}/{action}/{id}/{name}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional },
new { id = #"\d+" }
);
And then:
<%: Html.ActionLink("some text", "action", new { id = Model.Id, name = Model.Name }) %>

Create a route that allows the name to be specified as part of the url. Note that it's probably not actually used in resolving the article as it might not be unique. The id is the bit of information that is actually used to find and display the correct article, but the name is part of the url for context.
routes.MapRoute(
"Question",
"{controller}/{id}/{name}",
new { controller = "questions", action = "show", id = UrlParameter.Optional, name = UrlParameter.Optional },
new { id = "[0-9]+" } // constraint to force id to be numeric
);
Now, when you use Html.ActionLink() and specify the name as a parameter, the route will match and put in the name as a component of the url instead of a query parameter.
<%= Html.ActionLink( "questions", new { id = Model.ID, name = Model.NameForUrl } ) %>
Note that if you have multiple routes that might match you may need to use RouteLink and specify the route by name. Also, order matters.

Related

Firestore: set post id

How can I set id of post that I'm adding? I thought that getItemNextKey() returns id that will be assigned for the post, but it's not.
AddItem(data, downloadURLs) {
data.id= this.getItemNextKey(); // Persist a document id
data.upload = downloadURLs;
// console.log('this.uploadService.downloadURLs: ' + downloadURLs);
// console.log('data.upload: ' + data.upload);
this.db.collection('items').add(data);
}
I did this and it works now.
// Add a new document with a generated id
var addDoc = this.db.collection('items').add(data).then(ref => {
var updateNested = this.db.collection('items').doc(ref.id).update({
id: ref.id
});
});
As stated in the official docs
When you use set() to create a document, you must specify an ID for
the document to create. For example:
db.collection("cities").doc("new-city-id").set(data);
If you dont want to set an ID yourself you can use add
But sometimes there isn't a meaningful ID for the document, and it's
more convenient to let Cloud Firestore auto-generate an ID for you.
You can do this by calling add():

RALLY API: Could not set value for Tags: Cannot use type ObjectReference in attribute Tags

I am trying to create a new story in Rally.
Using: https://rally1.rallydev.com/slm/webservice/1.40/RallyService
Below is the code
var parentStory = rallyService.query(Workspace, Projs["xxx"], true, true, "HierarchicalRequirement", query, "", true, 1, 20).Results[0] as HierarchicalRequirement;
var tag = new Tag[1];
tag[0] = new Tag()
{
Archived = true,
ArchivedSpecified = true,
CreationDate = DateTime.Now,
CreationDateSpecified = true,
Name = tagName,
};
var childStory = new HierarchicalRequirement
{
Name = feedback.FeedBackSubject,
Description = feedback.FeedBackDescription,
Parent = parentStory,
Owner = parentStory.Owner,
Tags = tag
};
return rallyService.create(childStory);
I am getting the following error: Could not set value for Tags: Cannot use type ObjectReference in attribute Tags
Thanks
I usually use the REST endpoints rather than SOAP but I would guess that you'll need to create your tag first before you reference it in the story you are creating. I think the error is due to the fact that the tag being passed in the array doesn't have a ref.

ActionLink for a Custom MapRoute with two URL Parameters

I have a custom MapRoute
context.MapRoute("participantByGender",
"Admin/Participants/{id}/{gender}",
new {
controller = "Admin",
action = "Participants",
id = UrlParameter.Optional,
gender = UrlParameter.Optional
}
and i need to have a link which specifies both the id and a default gender. I have this one, which works for choosing the id, but how would i alter this to include the id and the gender in the link?
#Html.ActionLink("Participants", "Participants", new { id = item.termId })
Simply use:
#Html.ActionLink("Participants", "Participants", new { id = item.termId,gender=model.property })

mvc RedirectToAction passing a parameter [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
RedirectToAction with parameter
I am in controller home, in ActionResult Id which has a list of string name get returned from a method. I want to RedirectToAction (Id2) using that list. In View -> Id2 the ViewData of that list name get is null, doesn;t contain the list of the Itemsn populated. How can I redirect from an actionResult to another view of another actionresult passing parameter?
Use like this
If there are more than one parameters then:
return RedirectToAction("actionname", new { id = "id", name="name" }); // change parameters according to requirement
If you have only id as parameter then:
return RedirectToAction("actionname", new { id = "id" });
RedirectToAction( new RouteValueDictionary(
new{
controller = "mycontroller",
action = "myaction",
id = "MyId"
}
));

Entity Framework the use of reference

I use
p.AuthorsReference.EntityKey = new System.Data.EntityKey("PetitionsContainer.Authors", "Id", authorId);
but I get entities in PetitionsContainer.Questions participate in the QuestionAuthor relationship.
0 related 'Author' were found. 1 'Author' is expected.
Now, the Author with the Id authorId is already in the database.
It is true that each question must have 1 author.
Though, can't I use AuthorsReference instead of something like p.Authors.Add(new Author())?
If you set up the reference you must also fill the author. You can try using this:
// Attach a dummy author to the context so that context believes that you
// loaded the author from the database
Author a = new Author { Id = authorId };
context.Authors.Attach(a);
// Now assign existing author to the question
question.Author = a;