在我的控制者中,我这样做是初步的:
using mylib.product;
using mylib.factory;
product p = new product();
factory f = new factory(p);
从部分角度看,我如何用“@model”关键词做同样的事?
增 编
在我的控制者中,我这样做是初步的:
using mylib.product;
using mylib.factory;
product p = new product();
factory f = new factory(p);
从部分角度看,我如何用“@model”关键词做同样的事?
增 编
我认为,你们需要将不止一个不同类别的例子转移给观点。 如果是,我建议为此使用“观点”。 与此类似:
// Controller
=========
product p = new product();
factory f = new factory(p);
....
// Add some value for p and f
ViewBag.Product = p;
ViewBag.Factory = f;
return View();
// View
=========
var p = (product) ViewBag.Product;
var f = (factory) ViewBag.Factory;
// now you have access to p and f properties, for example:
@Html.Label(p.Name)
@Html.Label(f.Address)
不要放弃观点Bag是一个动态的集装箱,你需要把它放在一种类型上,因为你想在观点中使用其价值。
如果你试图在你看来增加姓名/舱位,那么:
@using mylib.product;
我应该把这一模式同大家一样看待。
return View("ViewName");
and in the view;
@model Project.Namespace.Class
你们应当使用观点模式:
public class MyViewModel
{
public string Name { get; set; }
public string Address { get; set; }
}
将由控制者行动考虑:
public ActionResult Index()
{
product p = new product();
factory f = new factory(p);
var model = new MyViewModel
{
Name = p.Name,
Address = f.Address
}
}
之后,您的意见将严格归纳为这一看法模式:
@model MyViewModel
@Html.DisplayFor(x => x.Name)
@Html.DisplayFor(x => x.Address)
What do you have in your model classes. Generally if i use any framework or any library (Zend Framework) , my classes only have variable which is table name . I know that in complicated applications ...
I m looking to write a Ruby script which I can load into the Rails Console which will access data from the models I have created. I created a model called student using the following command and ...
Given the following example: class AnonymousSession << Struct.new(:location, :preferences) def valid? ... end def new_record? ... end end While this interface is sufficient to ...
Id like to create a model in rails that does not correlate to a table in the database. Instead the model should dynamically pull aggregrate data about other models. Example: I have a Restaurant ...
I m making a website with two different databases. Let s say one is DB1, and the other is DB2. I ve set up my database.php in the config folder, so they each have the correct host/password/username/...
For my assignment I need to develop FSP model for email server and client. I manage to write simple model which describes one user, server and his mailbox, but I am having problems changing this ...
I m in a databases course and the instructor wants us to develop an e-commerce app. She said we can use any framework we like, and now that we re halfway through the semester she decided that Rails ...
I ve fitted a VECM model in R, and converted in to a VAR representation. I would like to use this model to predict the future value of a response variable based on different scenarios for the ...