如何将查询字符串值传递给ASP.net MVC app中具有默认值的视图模型参数?
我试过但没有成功;
public ActionResult Index(MyAnotherVM filter){
// filter.p doesn't set passed value and it equals to 1
}
public class MyAnotherVM {
public int p { get { return 1; } set { } }
// or
public int p=1;
}
答案 0 :(得分:-1)
您可以使用TempData
version: '3'
services:
client:
build: ./client
volumes:
- ./client:/usr/src/app
ports:
- "4200:4200"
- "9876:9876"
links:
- api
command: bash -c "yarn --pure-lockfile && yarn start"
sidekiq:
build: .
command: bundle exec sidekiq
volumes:
- .:/api
depends_on:
- db
- redis
- api
redis:
image: redis
ports:
- "6379:6379"
db:
image: postgres
ports:
- "5433:5432"
api:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
使用传递的查询字符串数据
或者你可以借助查询字符串来构建它,比如
[HttpPost]
public ActionResult FillStudent(Student student1)
{
TempData["student"]= new Student();
return RedirectToAction("GetStudent","Student");
}
[HttpGet]
public ActionResult GetStudent(Student passedStd)
{
Student std=(Student)TempData["student"];
return View();
}
这会生成GET请求,例如
return RedirectToAction("GetStudent","Student", new {Name="John", Class="clsz"});
但请确保您有[HttpGet],因为RedirectToAction将发出GET请求(302)