I am new in MVC Framework, I have just developed application in web form application till now Please suggest me, may i start MV3 or MVC 5 ?
mercredi 6 mai 2015
404 after changing routes in ASP NET MVC application
I had working routes on my app that looked like this:
routes.MapRoute(
name: "Category",
url: "{name}-c{categoryId}",
defaults: new { controller = "Products", action = "Index", name = "ErrorName" },
namespaces: new[] { "B2B.Controllers" });
routes.MapRoute(
name: "InfoPage",
url: "{name}-i{id}",
defaults: new { controller = "InfoPages", action = "Details", name = "ErrorName" },
namespaces: new[] { "B2B.Controllers" });
I've changed the dash (-) to the hash (#) because spaces are changed in url to dashes.
url: "{name}#c{categoryId}",
url: "{name}#i{id}",
Now I've this same routes with only this one char changed and I get 404 on urls like this:
siteadess:1234/1.0.1-Podstawowa%23c4
I've also tried to change hash to under score and it didn't worked either.
Manipulate the url using routing
In my website i have the following route defined:
routes.MapRoute(
name: "Specific Product",
url: "product/{id}",
defaults: new { controller = "", action = "Index", id = UrlParameter.Optional }
);
in that way i want customers to be able to add the id of the product and get to the product page.
SEO advisors have said that it would be better if we could add a description of the product on the url, like product name or something. So the url should look like something like:
/product/my-cool-product-name/123
or
/product/my-cool-product-name-123
Of course the description is stored in the db and i cannot do that with a url rewrite (or can i?)
Should i add a redirection on my controller (this would seem to do the job, but it just doesn't feel right)
Umbraco 7 Custom Controllers not working
I have two umbraco sites, one on version 7.1.8 the other on 7.2.4. The site with 7.1.8 has several controllers all of which inherit from PluginController. Other than inheriting from PluginController there have been NO modifications to the models i.e. inheriting from Umbraco.Web.Models.RenderModel or in the view. It simply works just like normal asp.net MVC. The controllers have no reason to talk to Umbraco.
My second site however doesn't seem to want to work in the same way. Error messages insisting I used Umbraco.Web.Models.RenderModel etc.
Is there any way to tell Umbraco leave my controllers alone like in the first site?
Image uploader on register view
I have a process where a user can register and add a picture of himself via an image file stored locally. The problem I am facing with a lot of image browsers openly available is either they require something as follows:
@using (Html.BeginForm("FileUpload", "Home", FormMethod.Post,
new { enctype = "multipart/form-data" }))
I am not that knowledgeable in MVC,Can someone suggest the approach I should take in handling this issue?
Image should be uploaded on clicking Register. Almost all of the image uploaders I found had a dedicated button for uploading.
Dynamically accessing resource file properties from Razor
We have a partial view which renders a <ul> containing <li> items that represent menu items. These are currently static in structure, and handle multilingual with resource files as follows:
<li><a href="@Url.Action("commissionlist", "commissions")">@Resources.Labels.Commissions</a></li>
However, I need to dynamically build the menu structure. So I have a list of menu item objects, which each have a MenuResourceTag field.
How do I get from having a string representing the name of the property I need to look up (e.g. "Commissions") to accessing the value of the appropriate property on Resources.Labels?
I know the answer will involve reflection, but all the examples I've found of similar things require an instance of the Resources.Labels class, and I can't work out how to get it in Razor.
ASP.Net MVC - Two Step Authentication
Good Morning
In MVC there is a method in the manage controller being used. to generate a token.
var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);
Does anyone know where this generated token is saved. In the basic MVC example they use it to add a phone number and needs to be verified with the token being sms`d to the cellphone number supplied, this code is used to generate that token. But no where is that token being saved, there is no column in the db and is not being passed to the view in a hidden field. But the strange part is when you enter the code and submit it, it will do a comparison in the post method using the following
public async Task<ActionResult> VerifyPhoneNumber(string phoneNumber)
{
var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), phoneNumber);
// Send an SMS through the SMS provider to verify the phone number
return phoneNumber == null ? View("Error") : View(new VerifyPhoneNumberViewModel { PhoneNumber = phoneNumber });
}
I cannot figure out where the GenerateChangePhoneNumberTokenAsync method will find the generated token to compare with the token being passed in with the model. Do anyone of you have and idea of where this could be found.
Kind Regards