asp.net-mvc-2

asp.mvc model design

杀马特。学长 韩版系。学妹 提交于 2019-12-19 10:28:00
问题 I am pretty new to MVC and I am looking for a way to design my models. I have the MVC web site project and another class library that takes care of data access and constructing the business objects. If I have in that assembly a class named Project that is a business object and I need to display all projects in a view ... should I make another model class Project? In this case the classes will be identical. Do I gain something from doing a new model class? I don't like having in views

Pass more than one model to view

℡╲_俬逩灬. 提交于 2019-12-19 09:53:06
问题 public ActionResult Index() { var pr = db.products; return View(pr); } Firstly - I want to pass to the view more data - something like: public ActionResult Index() { var pr = db.products; var lr = db.linksforproducts(2) return View(pr,lr); } How do I read the lr data in the view? Secondly - on the view I have a table of products, and I want to add to the table a column with all the tags of this products. How do I get the tags for every product? now i create this code public class catnewModel

How to include a link in AddModelError message?

大城市里の小女人 提交于 2019-12-19 05:45:17
问题 I want to add a ModelState error, like so: ModelState.AddModelError("", "Some message, <a href="/controller/action">click here</a>) However, the link doesn't get encoded, and so is displayed like text. I tried using <%= Html.ValidationSummary(true, "Some message") instead of <%: Html.ValidationSummary(true, "Some message") But no luck. Anyone have any idea how to get this working? Cheers 回答1: The simpliest way (works also with MVC 4): In controller: ModelState.AddModelError("", "Please click

How to include a link in AddModelError message?

╄→尐↘猪︶ㄣ 提交于 2019-12-19 05:45:04
问题 I want to add a ModelState error, like so: ModelState.AddModelError("", "Some message, <a href="/controller/action">click here</a>) However, the link doesn't get encoded, and so is displayed like text. I tried using <%= Html.ValidationSummary(true, "Some message") instead of <%: Html.ValidationSummary(true, "Some message") But no luck. Anyone have any idea how to get this working? Cheers 回答1: The simpliest way (works also with MVC 4): In controller: ModelState.AddModelError("", "Please click

Edit and Continue does not Work in VS 2010 / ASP.Net MVC 2

强颜欢笑 提交于 2019-12-19 05:17:22
问题 Although Enable Edit and Continue is checked on the Web tab of my ASP.Net MVC 2 project, I cannot in fact change the source code while running. For example, if I try to edit a controller while paused in the debugger, I cannot change the file (acts as if read only). I found a related post Edit and continue in ASP.NET web projects, however The answers seem to suggest I should be able to at least edit the code, then reload the page to see the result. I don't know what the distinction is between

Handling 2 buttons submit Actions in a single View/Form - ASP.NET MVC 2 RTM

人盡茶涼 提交于 2019-12-19 04:07:13
问题 I have a View in which the user is able to upload a file to the server. In this view I also have 2 buttons: one to Upload a file and other to Download the last file imported. In my Controller I created 2 action methods: Import and Export. How could I manage to redirect each button click to the proper action method in my Controller? I have tried Html.ActionLink: <%= Html.ActionLink("Upload", "Import", "OracleFile")%> <%= Html.ActionLink("Download", "Export", "OracleFile")%> Html.ActionLink

My ASP.NET MVC2 application with Forms Authentication is blocking access even to Images, Styles and Scripts

心已入冬 提交于 2019-12-19 03:22:55
问题 I'm developing a MVC2 application and using Forms Authentication on it. The scripts, images and styles are all blocked to unlogged users and, consequently, the login page looks awful. It works well local, the problem is when I publish to the server. Does anyone has any idea WHY???? PS: The server IIS is version 7.5 My Web.config : <configuration> <system.web> <globalization culture="pt-BR" uiCulture="pt-BR" /> <httpRuntime requestValidationMode="2.0"/> <customErrors mode="Off" /> <compilation

How does asp.net MVC remember my incorrect values on postback?

北战南征 提交于 2019-12-19 02:49:26
问题 This is working, but how??? I have a controller action for a post: [AcceptVerbs(HttpVerbs.Post )] public ActionResult Edit(Person person) { bool isvalid = ModelState.IsValid; etc. The Person object has a property BirthDate, type DateTime. When i enter some invalid data in the form, say 'blabla' which is obvious not a valid Datetime, it fills all the (other) Person properties with the correct data and the BirthDate property with a new blank DateTime. The bool isvalid has the value 'false'. So

How to supress re-post when refreshing a page - ASP.NET MVC

一曲冷凌霜 提交于 2019-12-19 02:37:13
问题 I am building a wizard using asp.net mvc. currently when the user hits next (or previous) the form values are posted to an action which does any processing required and then renders the next view. the problem i am having is that if the users hit refresh in that new view they get prompted to re-post the form values which causes a ton of problems. In firefox i am getting the message: "To display this page, the application must send information that will repeat any action (such as a search or

JsTree Open a node then select a child node (using json_result)

大憨熊 提交于 2019-12-19 02:06:15
问题 I am having trouble with a JsTree I am using in an MVC2 project. I would like to create a function to deselect/close all nodes on the tree. Then open a specific node, and select a specific child node (I have the Id values for both). The trouble is that the select_node is always called before the open_node finishes, so the node is not selected, as the tree has not loaded the data yet, and the node ID does not exist. I first tried this function. $('#demo3').jstree('deselect_all'); $('#demo3')